本文将介绍通过使用Spire.Doc for .NET来删除Word中的脚注、尾注。在Word中插入脚注、尾注请参考这篇文章。
//实例化Document类的对象,并加载测试文档
Document document = new Document();
document.LoadFromFile("test.docx");
//获取第一节
Section section = document.Sections[0];
//遍历所有段落
foreach (Paragraph para in section.Paragraphs)
{
int index = -1;
//遍历段落中的子对象,并删除脚注、尾注
for (int i = 0, cnt = para.ChildObjects.Count; i < cnt; i++)
{
ParagraphBase pBase = para.ChildObjects[i] as ParagraphBase;
if (pBase is Footnote)
{
index = i;
break;
}
}
if (index > -1)
para.ChildObjects.RemoveAt(index);
}
//保存文档
document.SaveToFile("result.docx", FileFormat.Docx);
删除效果: