如何使用 Aspose Word 应用内置页脚样式?

How to apply built-in footer style using Aspose Word?

最近在用Aspose Word生成一些报表,有个小问题

目前我正在使用 DocumentBuilder 和 2 列 table 来组成页脚,第一列的系统名称向左对齐,而第二列的页码向右对齐。

一切都很好,但我不想让页脚看起来像纯文本一样沉闷,所以我想给页脚添加一些样式。

我想应用一些内置的页脚模板,比如 Alphabet 如下所示,是否可以使用 Aspose Word 来实现?

如果您的计算机上安装了 MS Word 2013,您很可能会在以下位置找到 Word 文档'Built-In Building Blocks.dotx':

C:\Users\Awais\AppData\Roaming\Microsoft\Document 楼 Blocks33\Built-In 楼 Blocks.dotx

Word 附带的预定义内置构建块条目存储在上述模板文档中。使用 Aspose.Words,您可以从中提取任何构建块并粘贴到另一个 Word 文档中。

GlossaryDocument class in Aspose.Words 表示此类构建基块。请尝试使用以下代码:

Document docBuildingBlocks = new Document(MyDir + @"Building Blocks.dotx");
Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

GlossaryDocument glossaryDocument = docBuildingBlocks.GlossaryDocument;
foreach (BuildingBlock buildingBlock in glossaryDocument.BuildingBlocks)
{
    if (buildingBlock.Gallery.ToString().StartsWith("Footer") &&
        buildingBlock.Name.Equals("ViewMaster (Vertical)"))
    {
        Section sec = (Section)buildingBlock.FirstChild;
        foreach (Node node in sec.Body.ChildNodes)
        {
            HeaderFooter hf = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary];
            hf.AppendChild(doc.ImportNode(node, true));
        }
    }
}

doc.Save(MyDir + @"15.6.0.docx");

希望,这对您有所帮助。

我在 Aspose 工作,担任开发人员传播者。