0
到目前爲止,代碼被讀取模板並用新值替換,最後用新值替換docx文件。任何人都可以告訴我如何以不同名稱保存替換的docx文件?通過閱讀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文件,它將對我非常有幫助。
發表的代碼無法正常顯示。請重新格式化您的文章。您可能還需要添加C#標記 – 2010-04-09 04:08:10