Spire.Doc for Java 14.4.9 现已正式发布。该版本支持将图表保存为模板,并新增 XValues 属性支持获取图表 X 轴的数据值,以及 YValues 属性支持获取指定系列 Y 轴的数据值。此外,还支持读取和设置图表数据标签的位置。同时,一些在转换 Word 到 PDF,HTML 到 Word 以及 Markdown 到 Word 时出现的问题也得以成功修复。更多详情如下。
新功能:
- 支持将图表保存为模板
- 新增 XValues 属性支持获取图表 X 轴的数据值,以及新增 YValues 属性支持获取指定系列 Y 轴的数据值。
- 支持读取和设置图表数据标签位置。
Document doc = new Document();
doc.loadFromFile(inputFile);
int count = 1;
for (Section sec : (Iterable extends Section>) doc.getSections()) {
for (Paragraph paragraph : (Iterable extends Paragraph>) sec.getParagraphs()) {
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) {
DocumentObject obj = paragraph.getChildObjects().get(i);
if (obj instanceof ShapeObject) {
ShapeObject shape = (ShapeObject) obj;
Chart chart = shape.getChart();
String fileName = outputFile + count + ".crtx";
chart.saveAsTemplate(fileName);
count++;
}
}
}
}
Document doc = new Document();
doc.loadFromFile(inputFile);
StringBuilder sb = new StringBuilder();
int number =1;
for (Section sec : (Iterable extends Section>) doc.getSections()) {
for (Paragraph paragraph : (Iterable extends Paragraph>) sec.getParagraphs()) {
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) {
DocumentObject obj = paragraph.getChildObjects().get(i);
if (obj instanceof ShapeObject) {
ShapeObject shape = (ShapeObject) obj;
Chart chart = shape.getChart();
sb.append("\r\n\r\n第" +number + "页:\r\n" + "获取所有X轴数据:");
for(int x = 0; x < chart.getXValues().getCount(); x++){
// 打印所有X轴数据值
ChartValue xVal = chart.getXValues().get(x);
sb.append( xVal.getStringValue() + " ");
}
ChartSeries series = chart.getSeries().get(0);
sb.append("\r\n获取Y轴数据:");
// 打印第一个系列所有的Y轴数据值
for(ChartValue yVal : (Iterable<ChartValue>)series.getYValues()){
sb.append(yVal.getValue() + " ");
}
}
}
}
number ++;
}
Document doc = new Document();
for (ChartDataLabelPosition position : ChartDataLabelPosition.values()) {
Section section = doc.addSection();
section.addParagraph().appendText(position.name());
Paragraph newPara = section.addParagraph();
ShapeObject shape = newPara.appendChart(ChartType.Pie, 500, 300);
Chart chart = shape.getChart();
chart.getSeries().get(0).hasDataLabels(true);
chart.getSeries().get(0).getDataLabels().setShowCategoryName(true);
chart.getSeries().get(0).getDataLabels().setShowValue(true);
chart.getSeries().get(0).getDataLabels().setPosition(position);
ShapeObject shape2 = newPara.appendChart(ChartType.Bubble, 500, 300);
Chart chart2 = shape2.getChart();
chart2.getSeries().get(0).hasDataLabels(true);
chart2.getSeries().get(0).getDataLabels().setShowCategoryName(true);
chart2.getSeries().get(0).getDataLabels().setShowValue(true);
chart2.getSeries().get(0).getDataLabels().setPosition(position);
}
doc.saveToFile(outputFile, FileFormat.Docx);
问题修复:
- 修复了转换 HTML 到 Word 时,部分图片尺寸未自动缩放的问题。
- 修复了转换 Word 到 PDF 时,程序抛出 “NullPointerException” 异常的问题。
- 修复了转换 Word 到 PDF 时,程序抛出 “There are too many styles in the document” 异常的问题。
- 修复了转换 Markdown 到 Word 时,表格以及图片丢失的问题。
- 修复了转换 Word 到 PDF 时,域更新失败的问题。
- 修复了填充控件内容时,程序抛出 “NullPointerException” 异常的问题。
- 修复了在多线程下读取文档数据时,程序抛出 “NullPointerException” 异常的问题。
获取 Spire.Doc for Java 14.4.9 请点击:







