// 创建一个新的文档对象
Document doc = new Document();
// 从文件中加载文档
doc.LoadFromFile("test.docx");
// 获取章节2
Spire.Doc.Section section2 = doc.Sections[1];
// 获取章节3
Spire.Doc.Section section3 = doc.Sections[2];
// 创建一个用于存储要移动的段落的列表
List<Paragraph> paragraphsToMove = new List<Paragraph>();
// 遍历章节2的第33到第38个段落,并将它们添加到要移动的段落列表中
for (int i = 32; i <= 37; i++)
{
Paragraph paragraph = section2.Paragraphs[i];
paragraphsToMove.Add(paragraph);
}
// 如果章节3的段落数量大于等于88
if (section3.Paragraphs.Count >= 88)
{
// 设置目标索引为87
int targetIndex = 87;
// 遍历要移动的段落列表
foreach (Paragraph paragraph in paragraphsToMove)
{
// 将段落插入到章节3的目标索引位置
section3.Paragraphs.Insert(targetIndex, paragraph);
// 更新目标索引
targetIndex++;
}
}
// 遍历章节2的第37到第33个段落
for (int j = 37; j >= 33; j--)
{
// 如果章节2的段落数量大于当前索引
if (section2.Paragraphs.Count > j)
{
// 从章节2中移除当前索引处的段落
section2.Paragraphs.RemoveAt(j);
}
}
// 将修改后的文档保存为output.docx文件格式
doc.SaveToFile("output.docx", FileFormat.Docx);
// 关闭文档对象
doc.Close();