使用Apache POI 4.0运行官方示例LineChars和ScatterChart时出现问题

Apache POI 4.0的官方示例LineChart和ScatterChart存在问题。 它们编译运行没有错误,但无法打开创建的Excel文件,说明存在不可读的内容。 Excel 2010和2016提供了从工作簿中恢复数据的选项,单击“是”后,将显示此对话框 。 可能是什么问题?

新的XDDF代码缺少在lineChartscatterChart设置scatterChart

/xl/charts/chart1.xml这看起来像:

  ...    

对于折线图..

添加:

 ... XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis); data.addSeries(xs, ys1); data.addSeries(xs, ys2); chart.plot(data); //setting the axis Ids to the LineChart chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(bottomAxis.getId()); chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(leftAxis.getId()); // Write the output to a file try (FileOutputStream fileOut = new FileOutputStream("ooxml-line-chart.xlsx")) { wb.write(fileOut); } ... 

LineChart.java

 ... XDDFChartData data = chart.createData(ChartTypes.SCATTER, bottomAxis, leftAxis); data.addSeries(xs, ys1); data.addSeries(xs, ys2); chart.plot(data); //setting the axis Ids to the ScatterChart chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(bottomAxis.getId()); chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(leftAxis.getId()); // Write the output to a file try (FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx")) { wb.write(fileOut); } ... 

ScatterChart.java

它会起作用。