如何从使用Apache POI的Excel US preadsheet图表信息? [英] How to get chart info from an Excel spreadsheet using Apache POI?

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

问题描述

是否有可能从Office中提取图表信息2007(XLSX / OpenXML的)■使用Apache POI preadsheet?我已经成功在s preadsheet阅读,甚至得到一个指向图表,但不知道如何才能挽救这部分如任何信息的部分图表类型,图表数据等。

Is it possible to extract chart information from an Office 2007 (xlsx / OpenXML) spreadsheet using Apache POI? I've managed to read in the spreadsheet and even get the part that refers to the chart but not sure how I can retrieve any info from this part e.g. Type of chart, chart data etc.

XSSFWorkbook xwb = new XSSFWorkbook("charts_lines.xlsx");

XSSFSheet sheet = xwb.getSheetAt(0);

我还可以通过封装部件重复检索表的一部分,但我不明白我怎么然后继续检索有关图表的信息?

I can also iterate through the package parts to retrieve the chart part, but I don't see how I then go on to retrieve any info about the chart?

请注意,我不感兴趣创建使用POI图表,只是多读图表信息的是可以做到的......我也不会在保存XLSX。我只想提取线条颜色,标签,数据,图表类型(饼图,线,棒材等)

Note, I'm not interested in creating charts using POI, just read as much chart info as is possible to do...I'm also not saving an xlsx. I simply wish to extract line colours, labels, data, chart type (pie, line, bar etc.)

推荐答案

有没有在目前高位再presentation,所以你需要向下落入XMLBeans的水平和工作与低CT平*的对象。

There isn't a high level representation at the moment, so you'll need to drop down into the xmlbeans level and work with the low level CT* objects.

有关图表工作表,还有的 XSSFChartSheet 的,这将给你一个CTChartsheet对象,它具有信息的一点点。

For Chart Sheets, there's XSSFChartSheet which will give you a CTChartsheet object, which has a little bit of info.

对于 XSSFChart 的和的 XSSFChartSheet 的(经常和图表工作表),则需要通过图纸去得到图表。与它的图表每片都应该具有一个绘图,图表获得从附图的联系,而不是片材本身

For both XSSFChart and XSSFChartSheet (regular and chart sheets), you'll need to go via the drawings to get the charts. Each sheet with charts on it should have one Drawing, and the charts get linked from the drawing, rather than the sheet itself.

由于r1090442(POI所以3.8或更新版本)中,有上XSSFDrawing的方法来给你所有的XSSFChart对象(这是围绕/charts/chart#.xml部分包装)。如果你使用的是真的老版的POI,使用CTDrawing得到图表的细节,抓住/charts/chart#.xml一部分corresponts,然后让XMLBeans的给你吧CT对象。无论哪种方式,会让你获得冠军,类型,数据范围等。

As of r1090442 (so POI 3.8 or newer), there's a method on XSSFDrawing to give you all the XSSFChart objects (which are wrappers around the /charts/chart#.xml part). If you're on a really really old version of POI, use the CTDrawing to get the details of the chart, grab the /charts/chart#.xml part that corresponts, and then have xmlbeans give you the CT objects for it. Either way that'll let you get the titles, types, data ranges etc.

这是一个有点繁琐了,所以请不要考虑补丁发送,如果你得到的东西好制定了与CTChart对象合作,POI!

It is a bit fiddly though, so do please consider sending in a patch to POI if you get something good worked out for working with the CTChart objects!

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

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