我正在尝试使用Microsoft Open Office SDK(v2.0)创建新的MS Word文档并插入新的合并字段,但下面的代码不起作用(当我保存结果时,合并字段不会出现流到文件并打开它)。我在互联网上搜索过但无法解决问题。
MemoryStream stream = new MemoryStream();
using (
WordprocessingDocument wordDocument = WordprocessingDocument.Create(stream,
DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
{
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
FieldCode fieldCode = new FieldCode(" MERGEFIELD MyMergeField ");
body.AppendChild(fieldCode);
mainPart.Document.Save();
}
return stream;
感谢您的帮助。