zoukankan      html  css  js  c++  java
  • aspose word for java添加页码并自动生成目录

    添加页码

    public void addHeaderFooter(Document doc){
        //创建页脚 页码
    			HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_PRIMARY);
    			doc.getFirstSection().getHeadersFooters().add(footer);
    
    			//页脚段落
    			Paragraph footerpara = new Paragraph(doc);
    			footerpara.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    			Run footerparaRun = new Run(doc);
    			footerparaRun.getFont().setName("宋体");
    			footerparaRun.getFont().setSize(9.0);//小5号字体
    			footerpara.appendChild(footerparaRun);
    			footerpara.appendField(FieldType.FIELD_PAGE, true);//当前页码
    			footerpara.appendChild(footerparaRun);
    			footer.appendChild(footerpara);
    }
    

    生成目录

    //将光标移到文档开始的位置
    builder.moveToDocumentStart();
    builder.insertBreak(BreakType.PAGE_BREAK);
    
    //设置目录的格式         
    //“目录”两个字居中显示、加粗、搜宋体
    builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    builder.setBold(true);
    builder.getFont().setName(FontName.SONG);
    builder.writeln("目录");
    //清清除所有样式设置
    builder.getParagraphFormat().clearFormatting();
    //目录居左
    builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
     //插入目录,这是固定的
    builder.insertTableOfContents("\o "1-3" \h \z \u");
    field.update();
    doc.updateFields();// 更新域
                doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_1).getFont().setSize(FontSize.FONT105);    //改变目录的字体大小
                doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_2).getFont().setSize(FontSize.FONT105);    //改变目录的字体大小
                doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_3).getFont().setSize(FontSize.FONT105);    //改变目录的字体大小
                doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_3).getParagraphFormat().setLineSpacing(18);//改变目录行距
    

    生成目录参考:https://blog.csdn.net/SThranduil/article/details/53436789

  • 相关阅读:
    音频文件的属性
    判断UITextField.text是否为空(转)
    digital audio properties
    对scrollView的属性contentSize contentOffset contentInset个人理解
    OC定义变参函数
    va_list、va_start、va_arg、va_end的原理与使用(转载)
    游标笔记
    oracle中删除重复数据
    IIS无法启动,错误代码127[转自Alibaba DBA Team]
    推进游标是Fetch不是Petch!~!
  • 原文地址:https://www.cnblogs.com/haohj/p/10340493.html
Copyright © 2011-2022 走看看