使用 Java 创建和编辑 Excel 文档 (.csv)
对于我正在从事的这个项目,我想获取多个 Excel 工作表,然后将它们合并为一个,根据需要操作数据,使所有内容都更具可读性。
打开文件、读取其内容、存储该内容、创建新文件 (.csv),然后将信息粘贴到我选择的组织中的最佳方式是什么?
我绝对需要坚持使用 java,因为这将是预先存在的自动化流程的一部分,我不想将所有内容都更改为另一种语言。
有没有我应该了解的有用的软件包?
非常感
谢贾斯蒂安
For this project I'm working on, I want to take multiple excel sheets and then merge them into one, manipulating the data as I please to make everything a little more readable.
What would be the best way to open files, read their contents, store that content, create a new file (.csv), then paste the information in the organization of my choosing?
I definitely need to stick to java, as this will be part of a pre-existing automated process and I don't want to have to change everything to another language.
Is there a useful package out there that I should know about?
Many thanks
Justian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为 Excel 中的任何严肃工作都应该考虑 Joel 的 让 Office 解决方案如果需要,您可以在远程调用的 Windows 计算机上为您完成此操作。然而,如果您的需求足够简单或者您确实需要一个纯 Java 解决方案,Apache 的 POI 库可以提供一个足够好的工作。
I think any serious work in Excel should consider Joel's solution of letting Office do it for you on a Windows machine you call remotely if necessary. If, however, your needs are simple enough or you really need a pure Java solution, Apache's POI library does a good enough job.
据我所知,csv不是特定于excel的,而只是一个“逗号分隔值”-文件。
所以这可能对你有帮助。
As far as I know, csv is not excel-specific, but rather just a "comma-separated values"-file.
So this might help you.
出于显而易见的原因,编写 CSV 文件通常非常简单。您可以编写自己的辅助类来完成此操作。需要注意的是,要确保任何输出中都没有分隔符。
读取 CSV 比较棘手。没有像 Python 那样的标准库(恕我直言,这是一种更好的语言,用于进行 CSV 处理),但如果你搜索它,周围有很多不错的免费实现。
最大的问题是程序中的内部表示:根据输入和输出的大小,将所有内容保留在内存中可能是不可能的。你能一次性完成所有事情吗? (我的意思是,读一些,写一些,等等)
您可能还想使用稀疏表示,而不仅仅是表示数组中的所有电子表格。
Writing CSV files is usually very simple, for obvious reasons. You can write your own helper class to do it. The caveat is to ensure that you do not have your delimeter in any of the outputs.
Reading CSV is trickier. There isn't a standard library like there is in Python (a much better language, IMHO, for doing CSV processing), but if you search for it there are a lot of decent free implementations around.
The biggest question is the internal representation in your program: Depending on the size of your inputs and outputs, keeping everything in memory may be out of the question. Can you do everything in one pass? (I mean, read some, write some, etc.)
You may also want to use sparse representations rather than just represent all the spreadsheets in an array.
也许你应该尝试一下这个:
Jxcell,它是一个java电子表格组件,可以读取/写入/编辑所有xls/xlsx/csv文件。
Maybe you should try this one:
Jxcell,it is a java spreadsheet component,and can read/write/edit all xls/xlsx/csv files.
试试这个代码
Try this code