java 我应该使用哪个库来从 Linux/Python 编写 XLS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/245225/
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 11:37:05  来源:igfitidea点击:

Which library should I use to write an XLS from Linux / Python?

javapythonxlsjexcelapihssf

提问by Jeremy Dunck

I'd love a goodnative Python library to write XLS, but it doesn't seem to exist. Happily, Jython does.

我很想有一个很好的原生 Python 库来编写 XLS,但它似乎不存在。令人高兴的是,Jython 做到了。

So I'm trying to decide between jexcelapi and Apache HSSF: http://www.andykhan.com/jexcelapi/tutorial.html#writinghttp://poi.apache.org/hssf/quick-guide.html

所以我试图在 jexcelapi 和 Apache HSSF 之间做出决定:http://www.andykhan.com/jexcelapi/tutorial.html#writing http://poi.apache.org/hssf/quick-guide.html

(I can't use COM automation because I'm not on Windows, and even if I was, I couldn't afford Office licenses.)

(我不能使用 COM 自动化,因为我不在 Windows 上,即使我是,我也买不起 Office 许可证。)

My initial thoughts are that POI/HSSF is very thorough, but also very Java-- everything seems a bit harder than it needs to be. Good documentation, but my head hurts trying to bridge the gap between what it describes and what I need to accomplish.

我最初的想法是 POI/HSSF 非常彻底,但也非常 Java——一切似乎都比它需要的要难一些。很好的文档,但是试图弥合它描述的内容和我需要完成的内容之间的差距时,我的头很痛。

jexcepapi seems to have a simpler, nicer (for me) interface, but doesn't have very good documentation or community.

jexcepapi 似乎有一个更简单、更好(对我来说)的界面,但没有很好的文档或社区。

Which would you use, and why?

你会使用哪个,为什么?

回答by S.Lott

What's wrong with xlwt?

xlwt 有什么问题?

回答by technomalogical

+1 for xlwt. See Matt Harrison's blog for posts on how to use xlwtand how to deal with large spreadsheets. Also, check out the python-excelgroup on Google "If you use Python to read, write or otherwise manipulate Excel files".

+1 为 xlwt。有关如何使用 xlwt以及如何处理大型电子表格的帖子,请参阅 Matt Harrison 的博客。另外,请查看Google 上的python-excel组“如果您使用 Python 读取、写入或以其他方式操作 Excel 文件”。

回答by pvgoddijn

i personally dis-advise JExcel if you intent to use anything more then very simple text to excel and vice versa.

如果您打算使用比非常简单的文本更多的任何内容来表现出色,我个人不建议 JExcel,反之亦然。

the more advanced features are abstracted very leaky from the underlying (basically undocumented) low-level code / (documented) Excel specs.

更高级的功能是从底层(基本上未记录的)低级代码/(记录的)Excel 规范中抽象出来的。

another problem we ran into is jexcel fails fatally when encountering invalid formulas. and if you need to parse client supplied spreadsheets this is a problem.

我们遇到的另一个问题是 jexcel 在遇到无效公式时致命失败。如果您需要解析客户端提供的电子表格,这是一个问题。

also the new POI version support (almost) seemless both xls and xlsx at the same time.

此外,新的 POI 版本(几乎)同时支持 xls 和 xlsx。

回答by Ellery Newcomer

I'd use JExcelApi, but only because I've used it before. Never have touched HSSF. Biggest show-stopper I can recall is JExcelApi doesn't support multiple formats in one cell (e.g. half the text in bold, the other half in italic or something like that). I think in general JExcelApi is more limited than HSSF, but the limitations never got in my way.

我会使用 JExcelApi,但这只是因为我以前使用过它。从来没有接触过HSSF。我能记得的最大的障碍是 JExcelApi 不支持一个单元格中的多种格式(例如,一半的文本为粗体,另一半为斜体或类似的东西)。我认为总的来说 JExcelApi 比 HSSF 更受限制,但这些限制从来没有妨碍我。

And yes, documentation is sparse for the interface (and nonexistent for the underlying mechanisms), but I thought it was doable...

是的,接口的文档很少(并且底层机制不存在),但我认为这是可行的......

回答by ConcernedOfTunbridgeWells

Excel exposes the same OLE automation API used by VBA to anything that supports COM. You can use win32com (which is included with ActiveState Python by default) to manipulate spreadsheets in much the same way that you would do in VBA.

Excel 将 VBA 使用的相同 OLE 自动化 API 公开给任何支持 COM 的东西。您可以使用 win32com(默认包含在 ActiveState Python 中)以与在 VBA 中操作的方式大致相同的方式操作电子表格。