通过读取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 文件,这对我来说将非常有帮助。
Up to now code is read the template and replace with new values and finally replace the docx file with new values. Can any one please tell me how to save the replaced docx file in diffrent name?.
My code is bellow.
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);
}
}
If any one help me with this creating new docx file by changing above code, it will be very helpful for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)