如何使用 apache POI 从 Excel 中删除图表? [英] How to remove charts from Excel using apache POI?

查看:59
本文介绍了如何使用 apache POI 从 Excel 中删除图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Apache POI 删除所有图表.

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;
}

但是在保存然后打开工作表时,它说 XML 损坏.

But on saving and then opening the sheet it says corrupted XML.

推荐答案

请尝试以下代码:

sheet.getDrawingPatriarch().getCTDrawing().setNil();

这篇关于如何使用 apache POI 从 Excel 中删除图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆