Spire.Office for Java 11.1.0 现已正式发布。在该版本中,Spire.Doc for Java 支持为表格应用自定义样式;Spire.XLS for Java 支持插入、获取、更新 Equation 公式;Spire.Presentation for Java 支持从形状中读取自定义数据;Spire.PDF for Java 支持将 PDF 对比结果保存到文件流 。此外,该版本还修复了许多已知问题。详细更新内容如下。
获取 Spire.Office for Java 11.1.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
Spire.Doc for Java
优化:
- 弃用 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 对象是否相等。
- 新增方法支持创建、获取、删除 图片项目符号。
- 新增 removeSelf() 方法支持移除样式。
- 支持为表格应用自定义样式。
- 支持从模板克隆样式。
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();
document.getStyles().get("style1").removeSelf();
Document doc = new Document();
Section section = doc.addSection();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.Table_Style, "TestTableStyle1");
tableStyle.setHorizontalAlignment(RowAlignment.Center);
tableStyle.getBorders().setColor(Color.BLUE);
tableStyle.getBorders().setBorderType(BorderStyle.Single);
Table table = section.addTable();
table.resetCells(1, 1);
table.getRows().get(0).getCells().get(0).addParagraph().appendText("Aligned to the center of the page");
table.setPreferredWidth(PreferredWidth.fromPoints(300));
table.applyStyle(tableStyle);
// table.getFormat().setStyle(tableStyle);
doc.saveToFile(outputDocxFile, FileFormat.Docx);
doc.copyStylesFromTemplate(inputFile_2); // Accepts file path as String
doc.copyStylesFromTemplate(doc2); // Accepts another Document object
问题修复:
- 修复了结构化文档时,程序挂起的问题。
- 修复了对比目录内容失败的问题。
- 修复了转换 Word 到 PDF,程序挂起的问题。
- 修复了转换 Word 到 PDF,表格布局不正确的问题。
- 修复了转换 Word 到 PDF,文本位置不正确的问题。
- 修复了遵循 WPS 规则转换 Word 到 PDF,文本换行不正确的问题。
- 修复了转换 MHT 到 PDF,程序挂起的问题。
- 修复了 Avira 免费安全套件扫描 spire.doc.jar 存在病毒的问题。
- 修复了转换 Word 到 PDF 时,段落缩进不正确的问题。
- 修复了转换 Word 到 PDF 时,表格中的图片排版不正确的问题。
- 修复了遵循 WPS 规则转换 Word 到 PDF 时,效果不正确的问题。
- 修复了转换 Word 到 Markdown 时,程序抛出 NullPointerException 异常的问题。
- 修复了转换 Word 到 PDF 时,程序抛出 NullPointerException 异常的问题。
- 修复了更新目录域时,程序挂起的问题。
- 修复了更新页码域失败的问题。
- 修复了转换 Word 到 PDF 时,程序抛出 "java.lang.IllegalStateException: Unexpected ST_TrueFalse value" 异常的问题。
Spire.XLS for Java
新功能:
- 插入、获取、更新 Equation 公式。
- 支持 F.INV 公式。
- 支持 T.INV.2T 公式。
// 插入Equation
sheet.getEquations().addEquation(11, 0, 100, 100, "x_{1}^{2}");
// 获取Equation
String mathML = sheet.getEquations().get(0).exportMathML();
String LaTex = sheet.getEquations().get(0).exportLaTex();
// 更新Equation
IXlsEquation equation1 = sheet.getEquations().get(0);
equation1.updateByLaTexText("\\begin{pmatrix} \r\n 1 & 0 \\\\ \r\n 0 & 1 \r\n \\end{pmatrix} \r\n \\left(x-1\\right)\\left(x+3\\right) \\left(x-1\\right)\\left(x+3\\right)");
worksheet.getCellRange("A2").setFormula("=F.INV(0.99, 100, 200)");
worksheet.getCellRange("A2").setFormula("=T.INV.2T(0.05, 10)");
问题修复:
- 修复了转换 HTML 到 Excel,程序抛出 “ArrayIndexOutOfBoundsException” 异常的问题。
- 修复了计算公式耗时长的问题。
- 修复了转换 XLSX 到 XLS,公式多出蓝色背景的问题。
- 修复了转换 Excel 到 PDF,多出边框的问题。
- 修复了保存 XLS 到 XLSX,程序抛出 “NullPointerException” 异常的问题。
- 修复了当单元格中包含嵌入式图片时,复制该内容至其他 Excel 工作簿失败的问题。
- 修复了转换 Excel 到 PDF,程序抛出 “NullPointerException” 异常的问题。
- 修复了 Excel 插入图片后因文件句柄未释放导致无法删除本地图片的问题。
Spire.PDF for Java
新功能:
- 支持将 PDF 对比结果保存到文件流。
// Create a new PdfDocument object 'pdf1' to work with the first PDF file
PdfDocument pdf1 = new PdfDocument();
// Load the first PDF file from the specified path
pdf1.loadFromFile("ComparePdfDocument_1.pdf");
// Create a new PdfDocument object 'pdf2' to work with the second PDF file
PdfDocument pdf2 = new PdfDocument();
// Load the second PDF file from the specified path
pdf2.loadFromFile("ComparePdfDocument_2.pdf");
// Create a PdfComparer object 'compare' with 'pdf1' and 'pdf2' as parameters for comparison
PdfComparer compare = new PdfComparer(pdf1, pdf2);
// Set the page ranges to be compared using the options of the comparer
compare.getOptions().setPageRanges(0, pdf1.getPages().getCount() - 1, 0, pdf2.getPages().getCount() - 1);
String result = "output.pdf";
File outFile = new File(result);
// Create an output stream to write the document to the output file
OutputStream outputStream = new FileOutputStream(outFile);
// Compare the PDF documents and save
compare.compare(outputStream);
// Dispose of system resources associated with 'pdf1'
pdf1.dispose();
// Dispose of system resources associated with 'pdf2'
pdf2.dispose();
问题修复与优化:
- 优化了 PDF 转图片的性能表现。
- 修复了 OFD 转 PDF 时可能出现内存溢出的问题。
- 改善了 PDF 转 Word 后在 WPS 中打开时的显示效果。
- 修复了打印 PDF 时背景色和部分字体效果不一致的问题。
- 优化了 PDF 转流式 Word 文档的布局效果。
- 修复了 PdfTrueTypeFont 在多线程环境下可能引发的异常问题。
- 修复了使用 “Yu Mincho” 字体生成内容不正确的问题。
- 修复了 PDF 转 PDF/A-1A 时文本错位的问题。
- 修复了表格内容提取结果中多出空格的问题。
- 修复了 PDF 转图片时公式丢失的问题。
- 修复了 PDF 转 HTML 时文本重叠的问题。
- 修复了加载 PDF 文档时抛出 “structure is not valid” 异常的问题。
- 修复了添加文本水印后保存文档时可能抛出 ArrayIndexOutOfBoundsException 异常的问题。
- 修复了 SVG 转 PDF 时内容不一致的问题。
- 修复了 OFD 转 PDF 过程中出现异常字符串解析错误的问题。
- 修复了 OFD 转 PDF 后内容不正确的问题。
Spire.Presentation for Java
新功能:
- 支持读取形状中的客户数据。
- 支持设置音频的淡入/淡出效果持续时间。
- 支持裁剪音频播放区间。
- 支持设置表格透明度。
- 支持在转换过程中解析 WEBP 格式图片。
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
List dataList = ppt.getSlides().get(0).getShapes().get(0).getCustomerDataList();
System.out.println(dataList.size());
for(int i = 0; i < dataList.size(); i++)
{
String name = dataList.get(i).getName();
String content = dataList.get(i).getXML();
}
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
Rectangle2D.Double audioRect = new Rectangle2D.Double(220, 240, 80, 80);
IAudio audio=ppt.getSlides().get(0).getShapes().appendAudioMedia(inputFile_1, audioRect);
// 设置音频播放开始时的淡入效果持续时间为 13 秒
audio.setFadeInDuration(13000f);
// 设置音频播放结束时的淡出效果持续时间为 20 秒
audio.setFadeOutDuration(20000f);
ppt.saveToFile(outputFile, FileFormat.PPTX_2016);
ppt.dispose();
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
Rectangle2D.Double audioRect = new Rectangle2D.Double(220, 240, 80, 80);
IAudio audio = ppt.getSlides().get(0).getShapes().appendAudioMedia(inputFile_1, audioRect);
// 设置音频的起始裁剪时间为 8 秒
audio.setTrimFromStart(8000f);
// 设置音频的结束裁剪时间为 13 秒
audio.setTrimFromEnd(13000f);
ppt.saveToFile(outputFile, FileFormat.PPTX_2016);
ppt.dispose();
Presentation presentation = new Presentation();
presentation.loadFromFile("data/test.pptx");
Double[] widths = new Double[]{100d, 100d, 150d, 100d, 100d};
Double[] heights = new Double[]{15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d, 15d};
//添加表格
ITable table = presentation.getSlides().get(0).getShapes().appendTable((float) presentation.getSlideSize().getSize().getWidth() / 2 - 275, 90, widths, heights);
//设置范围是1-0,表格默认颜色为黑色
table.getFill().setTransparency(0.5f);
//设置具体表格颜色
table.get(0,0).getFillFormat().setFillType(FillFormatType.SOLID);
table.get(0,0).getFillFormat().getSolidColor().setColor(Color.BLUE);
presentation.saveToFile("result.pptx",FileFormat.PPTX_2016);
问题修复:
- 修复了添加Latex公式程序抛“NullPointerException”异常的问题。
- 修复了 Avira 安全套件对 spire.presentation.jar 误报病毒的问题。
- 修复了使用 "\dots" 公式,程序报 “NullPointerException” 的问题。
- 修复了PPT 转 PDF,内容不一致的问题。







