How to remove charts from Excel using apache POI?

[亡魂溺海] 提交于 2019-12-24 09:54:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!