コード例 #1
0
ファイル: WordExportService.cs プロジェクト: ywscr/EasyNPOI
        /// <summary>
        /// 替换模板中的占位符
        /// </summary>
        /// <param name="word"></param>
        private void ReplacePlaceholders <T>(XWPFDocument word, T wordData) where T : class, new()
        {
            if (word == null)
            {
                throw new ArgumentNullException("XWPFDocument 对象为空");
            }

            var basicReplacements = PlaceholderHelper.GetBasicReplacements(wordData);
            var gridReplacements  = PlaceholderHelper.GetGridReplacements(wordData);

            NPOIWordHelper.ReplaceInWord(word, basicReplacements, gridReplacements);
        }
コード例 #2
0
ファイル: WordExportService.cs プロジェクト: ywscr/EasyNPOI
        /// <summary>
        /// 根据模板导出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tmplPath"></param>
        /// <param name="savePath"></param>
        /// <param name="wordData"></param>
        public void ExportByTemplate <T>(string tmplPath, string savePath, T wordData)  where T : class, new()
        {
            if (string.IsNullOrEmpty(tmplPath) || string.IsNullOrEmpty(savePath))
            {
                throw new ArgumentNullException("路径为空");
            }

            XWPFDocument word = NPOIWordHelper.GetXWPFDocument(tmplPath);

            ReplacePlaceholders(word, wordData);
            NPOIWordHelper.SaveXWPFDocument(savePath, word);
        }