我的版本里没有destSection.Blocks放啊
时间: 2023-09-11 19:08:43 浏览: 37
如果您使用的是较早的版本,可能会出现 `Section.Blocks` 属性不存在的情况。您可以尝试使用 `Section.Body` 属性代替 `Section.Blocks`。
以下是修改后的代码示例:
```csharp
// 打开源文档
Document sourceDoc = new Document("source.docx");
// 复制第2页到第4页的内容
Document cloneDoc = sourceDoc.Clone();
cloneDoc.Sections.Clear();
for (int i = 1; i <= 3; i++)
{
Section sourceSection = sourceDoc.Sections[i];
Section cloneSection = sourceSection.Clone();
cloneDoc.Sections.Add(cloneSection);
}
// 打开目标文档
Document destDoc = new Document("dest.docx");
// 插入复制的内容到目标文档的第5页
Section destSection = destDoc.Sections[4];
destSection.Body.Paragraphs.Clear();
destSection.Body.ChildObjects.Add(new Paragraph(destDoc));
destSection.Body.ChildObjects[0].InsertDocument(cloneDoc, FileFormat.Docx);
```
以上代码将从源文档中复制第2页到第4页的内容,并插入到目标文档的第5页。请注意,我们将 `Section.Blocks` 改为 `Section.Body.ChildObjects`。