Spire.Office for Java 10.10.0 已正式发布。在该版本中,Spire.Doc for Java 支持获取样式更改修订;Spire.PDF for Java支持设置 PdfTable 的列宽;Spire.Presentation for Java 支持将 Markdown 转换为 PPTX 文件。除此之外,一些在转换和操作Word、Excel、PDF和PPT文档时出现的问题也已成功被修复。更多新功能及问题修复详情如下。
获取Spire.Office for Java 10.10.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
Spire.Doc for Java
新功能:
- 支持接受或拒绝部分修订。
- 支持获取样式更改修订。
- 支持针对样式进行修订跟踪记录。
- 支持设置文档网格每行字符数。
Document document = new Document();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (int i = 0; i < revisionInfoCollection.getCount() ; i++) {
RevisionInfo revisionInfo=revisionInfoCollection.get(i);
if(revisionInfo.getRevisionType()== RevisionType.Format_Change){
revisionInfo.accept();
//reject
revisionInfo.reject();
i--;
}
}
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = ConvertUtil.GetNewEngineDocument();
document.loadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection= document.getRevisionInfos();
for (RevisionInfo revisionInfo : (java.lang.Iterable)revisionInfoCollection) {
if(revisionInfo.getRevisionType()==RevisionType.Format_Change){
if(revisionInfo.getOwnerObject() instanceof TextRange){
TextRange range = (TextRange)revisionInfo.getOwnerObject();
TestUtil.writeAllText(outputFile,"TextRange:"+range.getText()+"\r\n");
document.setRevisionsView(RevisionsView.Original);
TestUtil.writeAllText(outputFile,"Original bold:"+range.getCharacterFormat().getBold()+"\r\n");
document.setRevisionsView(RevisionsView.Final);
TestUtil.writeAllText(outputFile,"Final bold:"+range.getCharacterFormat().getBold()+"\r\n");
}
}
}
document.close();
Document document = new Document();
document.loadFromFile("test.docx");
document.startTrackRevisions("e-iceblue");
for (int i=0; i<document.getSections().get(0).getParagraphs().get(0).getChildObjects().getCount();i++)
{
if (document.getSections().get(0).getParagraphs().get(0).getChildObjects().get(i).getDocumentObjectType()== DocumentObjectType.Text_Range)
{
TextRange tr = (TextRange) document.getSections().get(0).getParagraphs().get(0).getChildObjects().get(i);
tr.getCharacterFormat().setTextColor(Color.RED);
tr.getCharacterFormat().setFontSize(28);
tr.getCharacterFormat().setBold(true);
}
}
document.getSections().get(0).getParagraphs().get(1).appendText("aaa");
document.stopTrackRevisions();
document.saveToFile("test-out.docx");
sec.getPageSetup().setGridType(GridPitchType.Chars_And_Line);
sec.getPageSetup().setCharactersPerLine(30);
问题修复:
- 修复了接受修订效果不正确的问题。
- 修复了 Word 转 PDF 效果不正确的问题。
- 修复了不调用 AcceptChanges(),获取不到高亮颜色的问题。
- 修复了设置表格样式报错的问题。
- 修复了更新目录不正确的问题。/li>
- 修复了 HTML 转 Word 效果不正确的问题。
- 修复了转换 MHT 文件到 docx 乱码的问题。
- 修复了加载文档抛异常“IllegalArgumentException”的问题。
- 修复了加载文档抛“NullPointerException”的问题。
- 修复了移除内容控件效果不正确的问题。
- 修复了获取书签为空的问题。
- 修复了选中的复选框选中失败的问题。
- 修复了接受修订后,可编辑区域不能编辑的问题。
- 修复了保存文档到 wps 格式,图片内容丢失的问题。
- 修复了使用 useHarfBuzzTextShaper(true) 时,Word 转 PDF 抛出异常的问题。
- 修复了使用 replaceBookmarkContent 抛异常 “NullPointerException”的问题。
- 修复了 替换效果不正确的问题。
- 修复了 StructureDocumentTagCell.removeSelfOnly,程序抛异常 “Cannot remove because there is no parent.”的问题。
Spire.XLS for Java
优化:
- 优化了加载 Excel 文档时的内存消耗。
问题修复:
- 修复了获取复选框失败的问题。
- 修复了配置 JVM 最大内存时,加载 Excel 文档程序挂起的问题。
- 修复了转换 Excel 到 PDF 时,内存溢出的问题。
- 修复了拷贝工作表时,格式不一致的问题。
- 修复了保存 Excel 文档时,程序抛出 “error in set print area” 异常的问题。
- 修复了加载 Excel 文档时,程序抛出 “Input string was not in the correct format” 异常的问题。
Spire.PDF for Java
新功能:
- 支持设置 PdfTable 列宽。
// Create PDF document
PdfDocument doc = new PdfDocument();
// Set margins
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.setTop(unitCvtr.convertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setBottom(margin.getTop());
margin.setLeft(unitCvtr.convertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point));
margin.setRight(margin.getLeft());
// Add a page
PdfPageBase page = doc.getPages().add(PdfPageSize.A4, margin);
// Add table
PdfTable table = new PdfTable();
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));
table.getStyle().setBorderPen(new PdfPen(brush, 0.5f));
table.getStyle().getHeaderStyle().setStringFormat(new PdfStringFormat(PdfTextAlignment.Center));
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
table.getStyle().setCellPadding(2);
table.getStyle().setHeaderSource(PdfHeaderSource.Rows);
table.getStyle().setHeaderRowCount(1);
table.getStyle().setShowHeader(true);
// Set header font and style
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 12));
table.getStyle().getHeaderStyle().setFont(font);
table.getStyle().getHeaderStyle().setBackgroundBrush(PdfBrushes.getCadetBlue());
PdfTrueTypeFont fontBody = new PdfTrueTypeFont(new Font("SimSun", Font.PLAIN, 10));
// Set even row font
table.getStyle().getDefaultStyle().setFont(fontBody);
// Set odd row font
table.getStyle().getAlternateStyle().setFont(fontBody);
// false: distribute by total width proportion, true: use set column width
table.getStyle().isFixWidth(true);
// Define data
String[] data = {"1;2;3;4;5",
"A1;B1;1,391,190,000;18.2%; ",
"A1;B1;126,490,000;1.66%; ",
"A1;B1;65,648,054;0.86%; ",
"A1;B1;82,665,600;1.08%; ",
"A1;B1;37,119,000;0.49%; ",
"A1;B1;327,216,000;4.29%; "
};
String[][] dataSource = new String[data.length][];
for (int i = 0; i < data.length; i++) {
dataSource[i] = data[i].split("[;]", -1);
}
table.setDataSource(dataSource);
for(int i = 0; i < table.getColumns().getCount(); i++)
{
PdfColumn column = table.getColumns().get(i);
column.setWidth(50);
column.setStringFormat(new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
}
// Add table to page
table.draw(page, new Point2D.Float(0, 50));
// Save document
doc.saveToFile("addTable.pdf", FileFormat.PDF);
Spire.Presentation for Java
新功能:
- 支持转换 Markdown 为 PPTX 文件。
- 新增 AddFromSVGAsShape 方法,用于将 SVG 转换为 Shape。
Presentation pt = new Presentation();
pt.loadFromFile("input.md", FileFormat.Markdown);
pt.saveToFile("output.pptx", FileFormat.PPTX_2013);
pt.dispose();
Presentation ppt = new Presentation();
ppt.loadFromFile("input.pptx");
for (int i = 0; i < ppt.getSlides().getCount(); i++)
{
ppt.getSlides().get(i).getShapes().addFromSVGAsShapes("in.svg");
}
ppt.saveToFile("output.pptx", FileFormat.PPTX_2013);
ppt.dispose();
问题修复:
- 修复了扫描图片,程序抛 “java.lang.OutOfMemoryError”的问题。
- 修复了扫描图片,结果数据不正确的问题。
Spire.Barcode for Java
问题修复:
- 修复了扫描图片,程序抛 “java.lang.OutOfMemoryError”的问题。
- 修复了扫描图片,结果数据不正确的问题。







