问题
I will need to remove all the charts using Apache POI.
I tried using the following code :-
public XSSFSheet removeCharts(XSSFSheet sheet) {
XSSFDrawing drawing = sheet.getDrawingPatriarch();
List<XSSFChart> charts = drawing.getCharts();
charts.stream().forEach(v -> {
v.getCTChartSpace().setNil();
});
return sheet;
}
But on saving and then opening the sheet it says corrupted XML.
回答1:
Please try the below code :
sheet.getDrawingPatriarch().getCTDrawing().setNil();
来源:https://stackoverflow.com/questions/46646716/how-to-remove-charts-from-excel-using-apache-poi