Spire.Doc for Java 14.1.0 现已正式发布。该版本优化了与列表样式相关的方法,支持创建/获取/删除图片项目符号,比较两个 ListLevel 对象,并支持通过内置模板创建单级和多级列表。此外,一些在在转换 Word 到 PDF 和 MHT 到 PDF 时出现问题也已成功被修复。详情如下。
优化:
- 弃用 Document.getListStyles() 属性,替换为 Document.getListReferences()。
- 回收 ListStyle 对外公开的构造方法,新增 StyleCollection.add(ListType listType, string name) 方法创建 ListStyle。
- 变更段落应用 ListStyle 的方法。
- 回收 ListFormat.getCurrentListStyle() 方法,变更为 ListFormat.getCurrentListRef() 方法。
ListStyle listStyle = document.getStyles().add(ListType.Numbered, "levelstyle");
listStyle.isCustomStyle(true);
ListLevelCollection levels = listStyle.getListRef().getLevels();
levels.get(0).setPatternType(ListPatternType.Arabic);
levels.get(0).setStartAt(1);
levels.get(0).getCharacterFormat().setFontName("Trebuchet MS");
paragraph.getListFormat().applyStyle(ListStyle listStyle);
paragraph.getListFormat().setListLevelNumber(int leverNumber)
或
paragraph.getListFormat().applyListRef(ListDefinitionReference list, int leverNumber);
新功能:
- 在 ListCollection 中新增 add(ListTemplate template) 方法,可通过内置模板创建多级列表。
- 在 ListCollection 中新增 addSingleLevelList(ListTemplate listTemplate) 方法,可快速创建单级列表。
- 新增 ListLevel.equals(ListLevel level) 方法比较两个 ListLevel 对象是否相等。
- 新增方法支持创建、获取、删除 图片项目符号。
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建默认项目符号列表模板
ListTemplate template = ListTemplate.Bullet_Default;
ListDefinitionReference listRef = document.getListReferences().add(template);
// 创建默认编号列表模板
ListTemplate template1 = ListTemplate.Number_Default;
listRef = document.getListReferences().add(template1);
listRef.getLevels().get(2).setStartAt(4);// 设置第3级列表从数字4开始
// 添加段落并应用编号列表样式(第2级)
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
// 应用第2级(索引从0开始,1表示第2级)
paragraph.getListFormat().applyListRef(listRef, 1);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 2");
// 应用第3级
paragraph.getListFormat().applyListRef(listRef, 2);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 3");
// 应用第2级
paragraph.getListFormat().applyListRef(listRef, 1);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 4");
// 应用第3级
paragraph.getListFormat().applyListRef(listRef, 2);
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建阿拉伯数字编号列表模板(如 "1.", "2.", ...)
ListTemplate template = ListTemplate.Number_Arabic_Dot;
// 使用 addSingleLevelList 创建单级列表引用
ListDefinitionReference listRef = document.getListReferences().addSingleLevelList(template);
int levelcount = listRef.getLevels().getCount();//判断层级
boolean res=listRef.isMultiLevel();
// 添加第一个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
paragraph.getListFormat().applyListRef(listRef, 0);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 2");
paragraph.getListFormat().applyListRef(listRef, 0);
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建自定义项目符号列表样式
ListStyle listStyle = document.getStyles().add(ListType.Bulleted, "bulletList");
// 获取该列表样式的各级别配置
ListLevelCollection Levels = listStyle.getListRef().getLevels();
// 为第1级设置图片项目符号
Levels.get(0).createPictureBullet();
Levels.get(0).getPictureBullet().loadImage(imag_Path_1);
// 为第2级设置图片项目符号
Levels.get(1).createPictureBullet();
Levels.get(1).getPictureBullet().loadImage(imag_Path_2);
// 添加第一个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
paragraph.getListFormat().applyStyle(listStyle);
// 添加第二个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1.1");
paragraph.getListFormat().applyStyle(listStyle);
paragraph.getListFormat().setListLevelNumber(1);
//删除第1级的图片项目符号
Levels.get(0).deletePictureBullet();
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
问题修复:
- 修复了结构化文档时,程序挂起的问题。
- 修复了对比目录内容失败的问题。
- 修复了转换 Word 到 PDF,程序挂起的问题。
- 修复了转换 Word 到 PDF,表格布局不正确的问题。
- 修复了转换 Word 到 PDF,文本位置不正确的问题。
- 修复了遵循 WPS 规则转换 Word 到 PDF,文本换行不正确的问题。
- 修复了转换 MHT 到 PDF,程序挂起的问题。
- 修复了 Avira 免费安全套件扫描 spire.doc.jar 存在病毒的问题。
获取 Spire.Doc for Java 14.1.0 请点击:







