用 Java 创建 Excel 图表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2229490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:10:35  来源:igfitidea点击:

Create Excel Charts in Java

javaexcelchartsapache-poi

提问by Jeff Storey

I've been using Apache POI to create and modify Excel spreadsheets, but I'm wondering if there is a way (even if it's with a different library, preferably open source) to create charts in Excel in the new xlsx format. It looks like POI has an HSSFChart but I believe that's for the older format (please correct me if I'm wrong). Has anyone used a Java solution to create charts in Excel?

我一直在使用 Apache POI 创建和修改 Excel 电子表格,但我想知道是否有一种方法(即使它使用不同的库,最好是开源的)以新的 xlsx 格式在 Excel 中创建图表。看起来 POI 有一个 HSSFChart,但我相信这是旧格式(如果我错了,请纠正我)。有没有人使用 Java 解决方案在 Excel 中创建图表?

回答by Nathan

An option may be to create the charts beforehand and use POI to write the values where the chart can read them.

一个选项可能是预先创建图表并使用 POI 写入图表可以读取它们的值。

That is what I ended up doing, and it works great.

这就是我最终做的,而且效果很好。

Make sure if you have formulas in your data, you go through every cell in the spreadsheet and evaluate them before writing it out to disk.

确保您的数据中是否有公式,在将电子表格写入磁盘之前,您会检查电子表格中的每个单元格并对其进行评估。

回答by Mariano Desanze

I have not used the Java edition of Aspose Cellsbut I've used the .NET edition and it is really nice. Over there it says that it can open and save XLSX. It's not free nor open source, though.

我没有用过Aspose CellsJava 版,但我用过 .NET 版,它真的很好。那边说可以打开并保存XLSX。不过,它不是免费的,也不是开源的。

回答by matt b

I prefer using JExcelto POI (the API is simpler) but it seems like they don't support the 2007 formats yet either.

我更喜欢使用JExcel到 POI(API 更简单),但似乎它们也不支持 2007 格式。