TrimToSize:
Hay un problema con el oficial ejemplos LineChart y ScatterChart para Apache POI 4.0. Ellos compilar y ejecutar sin errores, pero el archivo de Excel creado no se pueden abrir indica que no hay contenido ilegible. Excel 2010 y 2016 están dando la opción de recuperar los datos desde el libro y después pinchando sí, esto diálogo aparece. ¿Cuál podría ser el problema?
Axel Richter:
El nuevo XDDF
código le falta el ajuste de las axId
s en el lineChart
e scatterChart
.
En /xl/charts/chart1.xml
esto se parece a:
<c:lineChart>
...
<c:axId val="0"/>
<c:axId val="1"/>
</c:lineChart>
para un gráfico de líneas ..
Hacer añadiendo:
...
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);
}
...
en LineChart.java
y
...
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);
}
...
en ScatterChart.java
y funcionará.