OpenXML 合并文档 - 如何使用快捷会议工具查看内容

OpenXML Merging Documents - How to See Content using Productivity Tool

我也是新手,正在为 OpenXML 苦苦挣扎。我们基本上有一个 Word 模板,根据用户在我们拥有的网站中选择的记录数量,我们从数据库中提取记录并使用该模板创建一个 Word 文档。然后我们 assemble 将所有这些文档合并为一个主 Word 文档,提供给用户。我们使用 OpenXML 和 altchunks 来做到这一点:

string altChunkId = "AltChunkId" + itemNo.ToString();
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(                                     AlternativeFormatImportPartType.WordprocessingML, altChunkId);
using (FileStream fileStream = File.Open(createdFileName, FileMode.Open))
{
  chunk.FeedData(fileStream);
  fileStream.Close();
}
AltChunk altChunk = new AltChunk();
AltChunkProperties altChunkProperties = new AltChunkProperties();
MatchSource matchSrc = new MatchSource();
matchSrc.Val = true;
altChunkProperties.Append(matchSrc);
altChunk.AppendChild(altChunkProperties);
altChunk.Id = altChunkId;
mainPart.Document.Body.Append(altChunk);
mainPart.Document.Save();

当我在效率工具中打开其中一个模板文档时,我可以看到我期望的所有元素:

但是,当我查看 'master' 文档时,我只能找到 MatchSource:

我不明白的是为什么我在生成的主文档中看不到段落标签等。谁能帮助我了解我将如何查看这些信息?文档结构有问题吗?

这是因为 altchunk 合并到主文档的方式。 altchunks 不会更改主文档的 openxml 标记,但它会将文件添加为嵌入资源。把它想象成你在电子邮件中附加了一些东西,但没有把它添加到实际的电子邮件正文中。有一些第三方解决方案,如 Document Builder,将通过修改主文档标记来合并文档。然后你就可以在生产力工具中看到你期待的东西了。