【发布时间】:2018-10-14 22:11:00
【问题描述】:
我有一个包含多个页面的 Word 文档,我想使用 OpenXml SDK 将一些页面复制到新的 Word 文档中。我做了一些网络搜索,得到了下面的代码,它读取整个文档并复制到新文档中
string documentURL = filelocation;
byte[] docAsArray = File.ReadAllBytes(documentURL);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(docAsArray, 0, docAsArray.Length); // THIS performs doc copy
using (DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(stream, true))
{
// perform content control substitution here, making sure to call .Save()
// on any documents Part's changed.
}
File.WriteAllBytes(outputSplitDocpath, stream.ToArray());
}
现在,在上面的代码中,我怎样才能只读取特定页面并复制到新页面?请帮忙提出建议。谢谢
【问题讨论】:
标签: c# ms-word openxml openxml-sdk