到目前为止,代码读取模板并替换为新值,最后用新值替换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文件,那对我来说非常有帮助。
答案 0 :(得分:0)
Dim sw As StreamWriter = New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))
sw.Write(docText)
sw.Close()
sw.Dispose()