使用 Apache POI 4.0 运行官方示例 LineChars 和 ScatterChart

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


扬帆大鱼
浏览 188回答 1
1回答

小唯快跑啊

新XDDF代码缺少and 中的axIds设置。lineChartscatterChart在/xl/charts/chart1.xml这看起来像:<c:lineChart>&nbsp;...&nbsp;<c:axId val="0"/>&nbsp;<c:axId val="1"/></c:lineChart>对于折线图..做添加:...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.addSeries(xs, ys1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.addSeries(xs, ys2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.plot(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //setting the axis Ids to the LineChart&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(bottomAxis.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(leftAxis.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the output to a file&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try (FileOutputStream fileOut = new FileOutputStream("ooxml-line-chart.xlsx")) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wb.write(fileOut);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }...在 LineChart.java和...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XDDFChartData data = chart.createData(ChartTypes.SCATTER, bottomAxis, leftAxis);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.addSeries(xs, ys1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data.addSeries(xs, ys2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.plot(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //setting the axis Ids to the ScatterChart&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(bottomAxis.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(leftAxis.getId());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Write the output to a file&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try (FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx")) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wb.write(fileOut);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }...在 ScatterChart.java它会起作用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java