0

到目前为止,代码已读取模板并替换为新值,最后将 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 文件,那对我将非常有帮助。

4

1 回答 1

0
Dim sw As StreamWriter = New StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))
    sw.Write(docText)
    sw.Close()
    sw.Dispose()
于 2010-07-23T07:32:19.203 回答