Spire.Doc for Java 14.11.3 现已正式发布。该版本支持设置 Word 图表系列的样式,并修复了一些在转换 Word 到 PDF 以及 ODT 到 PDF 时出现的问题。详情如下。
新功能:
- 支持设置图表系列的样式,包括线条颜色、宽度、线型以及填充效果。
Document document = new Document();
document.loadFromFile(inputFile);
Section section = document.getSections().get(0);
for (Paragraph paragraph : (Iterable<? extends Paragraph>) section.getParagraphs()) {
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) {
if (paragraph.getChildObjects().get(i) instanceof ShapeObject) {
Chart chart = ((ShapeObject) paragraph.getChildObjects().get(i)).getChart();
// 1、线条格式:颜色、宽度、线型、虚线样式
Stroke stroke = chart.getSeries().get(0).getDataPoints().getFormat().getStroke();
stroke.getFill().setColor(Color.RED);
stroke.setWeight(2);
stroke.setLineStyle(ShapeLineStyle.Single);
stroke.setDashStyle(DashStyle.Solid);
// 2、纯色填充:填充类型、颜色、透明度
Fill fill = chart.getSeries().get(0).getDataPoints().getFormat().getFill();
fill.setFillType(FillType.Solid);
fill.setColor(Color.BLUE);
fill.setTransparency(0.3);
// 3、渐变填充:渐变类型、方向、角度、渐变光圈
Fill gradientFill = chart.getFormat().getFill();
gradientFill.setFillType(FillType.Shade);
gradientFill.setGradientType(GradientFillType.Linear);
gradientFill.setGradientDirection(GradientFillDirection.Linear_Down);
gradientFill.setGradientAngle(90);
gradientFill.getGradientStops().add(new GradientStop(0, Color.WHITE, 1));
gradientFill.getGradientStops().add(new GradientStop(1, Color.BLUE, 0.5));
// 4、图案填充:图案类型、前景色、背景色
Fill patternFill = chart.getLegend().getFormat().getFill();
patternFill.setFillType(FillType.Pattern);
patternFill.setPattern(PatternType.Percent_10);
patternFill.setForegroundColor(Color.RED);
patternFill.setBackgroundColor(Color.WHITE);
// 5、图片/纹理填充:图片源、透明度、拉伸或平铺
Fill imageFill = chart.getAxisX().getFormat().getFill();
imageFill.setFillType(FillType.Picture);
imageFill.setImage(imagePath);
imageFill.setImageTransparency(0.5);
imageFill.stretchImage(0, 0, 100, 100);
}
}
}
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
问题修复:
- 修复了更新目录,结果不正确的问题。
- 修复了 Word 转 PDF,脚注和正文中的角标编号位置偏下的问题。
- 修复了 Word 转 PDF,程序抛出 "java.lang.StackOverflowError" 异常的问题。
- 修复了 ODT 转 PDF,程序抛出 "java.lang.NullPointerException" 异常的问题。
获取 Spire.Doc for Java 14.11.3 请点击:







