到目前为止,代码已读取模板并替换为新值,最后将 docx 文件替换为新值。谁能告诉我如何以不同的名称保存替换的 docx 文件?
我的代码如下。
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
{
string docText = null;
using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
}
Regex regexText = new Regex("#ApplicationCompleteDate#");
docText = regexText.Replace(docText,DataHolding.ApplicationCompleteDate);
regexText = new Regex("#ApplicantPrivateAddress#");
docText = regexText.Replace (docText,UserDataHolding.ApplicantPrivateAddress);
using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream (FileMode.Create)))
{
sw.Write(docText);
}
}
如果有人通过更改上述代码来帮助我创建新的 docx 文件,那对我将非常有帮助。