Word格式处理控件Aspose.Words for .NET教程——如何删除页脚,但保留页眉完整

Aspose.Words For .NET是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

>>Aspose.Words for .NET已经更新至最新版,新增4大新功能,包括Xamarin不再需要单独的DLL,FindReplaceOptions类扩展了新属性,实现了“ Letterlike”符号的正确呈现以及支持在文本框范围内动态拉伸图像,以及3钟增强型功能,点击下载体验


文档中的每个节最多可以具有三个页眉和三个页脚(用于第一页,偶数页和奇数页)。如果要删除文档中的所有页脚,则需要遍历所有节并删除每个页脚节点。

下面的示例删除所有节中的所有页脚,但保留页眉不变。模板如下:

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();

Document doc = new Document(dataDir + "HeaderFooter.RemoveFooters.doc");

foreach (Section section in doc)
{
    // Up to three different footers are possible in a section (for first, even and odd pages).
    // We check and delete all of them.
    HeaderFooter footer;

    footer = section.HeadersFooters[HeaderFooterType.FooterFirst];
    if (footer != null)
        footer.Remove();

    // Primary footer is the footer used for odd pages.
    footer = section.HeadersFooters[HeaderFooterType.FooterPrimary];
    if (footer != null)
        footer.Remove();

    footer = section.HeadersFooters[HeaderFooterType.FooterEven];
    if (footer != null)
        footer.Remove();
}
dataDir = dataDir + "HeaderFooter.RemoveFooters_out.doc";

// Save the document.
doc.Save(dataDir);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值