使用Apache POI导入CSV数据 [英] Importing CSV data with Apache POI

查看:3867
本文介绍了使用Apache POI导入CSV数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Apache POI有效导入CSV数据?如果我有一个非常大的CSV文件,我想存储在我的Excel电子表格,那么我不想象,逐个单元格是最好的导入方式...?

How can I efficiently import CSV data with Apache POI? If I have a very large CSV file that I would like to store in my Excel spreadsheet, then I don't imagine that going cell-by-cell is the best way to import...?

推荐答案

Apache POI从未设计为调用CSV文件。虽然可以在Excel中打开CSV文件,但Excel具有自己的读取器,可自动导入。这是假设您的CSV具有.csv而不是.txt后缀。如果它有.txt后缀,请将其另存为.csv。所有你需要做的是右键点击CSV和用Excel打开。 Presto,CSV已导入到Excel中。

Apache POI was never designed to call on CSV files. While a CSV File may be opened in Excel, Excel has its own reader that does an auto import. This is assuming that your CSV has the .csv instead of the .txt suffix. If it has the .txt suffix, save it as a .csv. All then you have to do is right click on the CSV and Open With Excel. Presto, the CSV has been imported into Excel.

我假设您想要将数据从txt文件解析到Excel文件中。如果是这样,我建议您使用图书馆的 SuperCSV ,而不是试图让POI做某事从来没有设计过。它会将其全部加载到您选择的Bean,Map或List中,因为它会解析数据,然后您可以将它以您选择的格式写回到.csv文件中,或者使用JDBC-ODBC桥或Apache POI写入它直接进入和.XLS格式。添加一个额外的步骤,但是你完全控制了数据。

I am assuming that you are wanting to parse the data from a txt file into the Excel File. If that is the case I would suggest you use a Library liKe SuperCSV instead of trying to get POI to do something it was never designed to do. It will load it all into a Bean, Map or List of your choice as it parses the data and then you can either write it back in the format you chose into a .csv file or use a JDBC-ODBC Bridge or Apache POI to write it directly into and .XLS format. Adds an extra step, but then you have complete control of the data.

SuperCSV携带Apache2许可证,因此它应该适用于您选择使用的任何东西。

SuperCSV carries the Apache2 License, so it should be good for anything you choose to do with it.

或者只需在java中使用.split()函数,并将CSV解析成数组,并将数组加载到带POI的.xls中。

Or just use the .split() function in java and parse up the CSV into arrays and load the arrays into .xls with POI.

这篇关于使用Apache POI导入CSV数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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