asp.net根据word模板生成word以及pdf

public static void GenerateWord(string templateFile, string fileNameWord, string fileNamePdf, Dictionary bookmarks)
这是总体函数,四个参数分别为模板word地址,生成word文件地址,生成pdf文件地址,要替换的内容
bookmarks是不定个数的键值对,key是待替换内容,value是替换内容
如果不需要生成pdf,可以在
 //此处存储时,参数可选填,如需另外生成pdf,加入一个参数ref FileName,
            doc.SaveAs(ref FileName, ref FileFormat, ref LockComments,
                    ref missing, ref AddToRecentFiles, ref missing,
                    ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
                    ref SaveNativePictureFormat, ref SaveFormsData,
                    ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks,
                    ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
处,去掉第一个参数(代码中有注释)
并置函数参数为空,或去掉


函数中的文件地址均是指定的,可以由前台获取


public static void replace(Microsoft.Office.Interop.Word.Document doc, string strOldText, string strNewText)
这是一个子函数,用于替换文字内容,参数分别为操作的word文档,待替换文本,替换文本
这个函数在总函数中调用了


调用过程,见实例中button_onclick1()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Microsoft.Office.Interop.Word;

你可能感兴趣的:(asp.net根据word模板生成word以及pdf)