-3
文書を開いてストリームにコピーします。OpenXMLを使用して文書内のテキストを置換する
ストリームの前にドキュメントのテキストを置き換えることはできますか?
//wordTemplate - var with path to my word template
byte[] result = null;
byte[] templateBytes = System.IO.File.ReadAllBytes(wordTemplate);
using (MemoryStream templateStream = new MemoryStream())
{
templateStream.Write(templateBytes, 0, (int)templateBytes.Length);
using (WordprocessingDocument doc = WordprocessingDocument.Open(templateStream, true))
{
MainDocumentPart mainPart = doc.MainDocumentPart;
mainPart.Document.Save();
templateStream.Position = 0;
using (MemoryStream memoryStream = new MemoryStream())
{
templateStream.CopyTo(memoryStream);
result = memoryStream.ToArray();
}
}
}
この情報はお役に立ちましたか? .. http://stackoverflow.com/questions/18744660/find-and-replace-text-in-xml-file-using-c-sharp – NMathur
ターゲット - オープンワード文書、いくつかの文字列を変更し、ユーザーのためにダウンロードのために送信する – Fullbalanced
'Regex'を使ってテキストを置き換えることができます。それを 'WordprocessingDocument'の' StreamReader.ReadToEnd() 'に渡してください。注:これのほとんどを書き直す必要があります。あなたが最も簡単な方法に接近していないように見えるからです。 – gravity