使用OpenXml 2.9.0,我正在尝试插入另一个文件的内容。我正在为此提供OpenXml文档代码。插入后文件未打开。出现类似
的错误我的代码是
string fileName1 = @"c:\Users\Public\Documents\testabc.docx";
string fileName2 = @"c:\Users\Public\Documents\Source.docx";
using (WordprocessingDocument myDoc =
WordprocessingDocument.Open(fileName1, true))
{
string altChunkId = "AltChunkId1";
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk =
mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, altChunkId);
using (FileStream fileStream = File.Open(fileName2, FileMode.Open))
chunk.FeedData(fileStream);
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
mainPart.Document
.Body
.InsertAfter(altChunk, mainPart.Document.Body
.Elements<Paragraph>().Last());
mainPart.Document.Save();
}
有人可以帮助我吗?