彩票走势图

国产Word格式处理控件Spire.Doc功能演示:使用Java在 Word 中添加多级项目符号列表和多级编号列表

翻译|使用教程|编辑:李显亮|2021-08-11 10:18:12.060|阅读 429 次

概述:本文介绍使用Spire.Doc for Java在Word文档中添加多级项目符号列表和多级编号列表的方法。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

Spire.Doc for Java 是一款专业的Java Word组件,开发人员使用它可以轻松地将Word文档创建、读取、编辑、转换和打印等功能集成到自己的Java应用程序中。

本文介绍使用Spire.Doc for Java在Word文档中添加多级项目符号列表和多级编号列表的方法。点击此处下载最新版测试

代码如下:

import com.spire.doc.*;
import com.spire.doc.documents.*;

public class MultiLevelList {
    public static void main(String[] args) {
        //创建一个Document类的实例
        Document document = new Document();
        //添加Section
        Section sec = document.addSection();

        //添加段落
        Paragraph paragraph = sec.addParagraph();
        paragraph.appendText("Lists");
        paragraph.applyStyle(BuiltinStyle.Title);
        paragraph = sec.addParagraph();
        paragraph.appendText("Numbered List: ").getCharacterFormat().setBold(true);

        //创建编号列表样式
        ListStyle numberList = new ListStyle(document, ListType.Numbered);//编号列表
        numberList.setName("numberList");
        numberList.getLevels().get(1).setNumberPrefix("\u0000.");
        numberList.getLevels().get(1).setPatternType(ListPatternType.Arabic);
        numberList.getLevels().get(2).setNumberPrefix("\u0000.\u0001.");
        numberList.getLevels().get(2).setPatternType(ListPatternType.Arabic);

        //创建符号列表样式
        ListStyle bulletList= new ListStyle(document, ListType.Bulleted);//符号列表
        bulletList.setName("bulletList");

        //添加列表样式
        document.getListStyles().add(numberList);
        document.getListStyles().add(bulletList);

        //添加段落并应用列表样式
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 1");
        paragraph.getListFormat().applyStyle(numberList.getName());

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2");
        paragraph.getListFormat().applyStyle(numberList.getName());

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.1");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(1);

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.2");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(1);

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.2.1");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(2);
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.2.2");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(2);
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.2.3");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(2);

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.3");
        paragraph.getListFormat().applyStyle(numberList.getName());
        paragraph.getListFormat().setListLevelNumber(1);

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 3");
        paragraph.getListFormat().applyStyle(numberList.getName());

        paragraph = sec.addParagraph();
        paragraph.appendText("Bulleted List:").getCharacterFormat().setBold(true);

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 1");
        paragraph.getListFormat().applyStyle(bulletList.getName());
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2");
        paragraph.getListFormat().applyStyle(bulletList.getName());

        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.1");
        paragraph.getListFormat().applyStyle(bulletList.getName());
        paragraph.getListFormat().setListLevelNumber(1);
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 2.2");
        paragraph.getListFormat().applyStyle(bulletList.getName());
        paragraph.getListFormat().setListLevelNumber(1);
        paragraph = sec.addParagraph();
        paragraph.appendText("List Item 3");
        paragraph.getListFormat().applyStyle(bulletList.getName());

        //保存文档
        document.saveToFile("MultiLevelList.docx", FileFormat.Docx);
        document.dispose();
    }
}

多级列表效果:

国产Word格式处理控件Spire.Doc功能演示:在Java中将 WPS 文字文档转为 PDF


Spire.Doc for Java 4.8.0已发布。该版本支持检测文档是否被加密,增强了转换Word到PDF/HTML/SVG、HTML到Word、以及WPS到PDF的功能。此外,本次更新还修复了加载和比较Word文档时出现的问题。


整合所有格式API处理套包Spire.office for Java正在慧都网火热销售中!立马1分钟了解全部咨询!


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP