これまでのコードは、テンプレートを読み取って新しい値に置き換え、最後に 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ファイルを作成するのを手伝ってくれる人がいれば、それは私にとって非常に役に立ちます。