我目前正在开发一个项目,将3个文档合并为一个新项目。为了添加它们,我创建了一个AltChunk方法来包含这些文档。将多个Word文档样式合并为一个Open Xml
我的问题是在三者之间的造型上有冲突。因此,我的意思是我保存一张桌子,底下有红色文字。但是,一旦三者合并成新的文件,该文件的样式将重置为纯黑色文本。有没有办法将所有三种样式合并到这个新文档中?
下面是我如何在文档中合并的代码(我没有显示顶部,因为它到目前为止都是好的)。
using (WordprocessingDocument package = WordprocessingDocument.Create(fileName, DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
{
...
#region Append Non-Standard Section Template
var nssAltChunkId = "AltChunkIdNSS" + this.AopPlanId.Value.ToString();
var nssChunk = package.MainDocumentPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, nssAltChunkId);
using (var fileStream = new MemoryStream(nssBuffer))
{
nssChunk.FeedData(fileStream);
}
var nssAltChunk = new DocumentFormat.OpenXml.Wordprocessing.AltChunk();
nssAltChunk.Id = nssAltChunkId;
package.MainDocumentPart.Document.Body.InsertAfter(nssAltChunk, package.MainDocumentPart.Document.Body.Elements<Paragraph>().Last());
#endregion
... //Next 2 documents are the same way
package.MainDocumentPart.Document.Save();
}
任何帮助,将不胜感激。谢谢。
编辑:我更改为使用PowerTools中的DocumentBuilder,但是,仍然无法解决合并样式的问题。任何建议,将不胜感激。
实际上,Open Xml Power Tools的创建者Eric White给了我一个类似的答案。他提到重命名样式可以解决问题。尽管最终我没有这样做,因为这被标记为低优先级,目前客户不值得修复。 感谢您的回答。我会标记它。 – IyaTaisho