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

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

问题描述

我怎样才能有效地导入与Apache POI CSV数据?如果我有,我想在我的Excel US preadsheet来存储一个非常大的CSV文件,然后我不想象去细胞通过细胞是导入的最佳方法...?

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文件的调用。虽然CSV文件可在Excel中打开时,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做一些它从来就没有做设计。因为它分析数据,将它全部加载到您所选择的豆,地图或列表,然后你可以把它写回你选择到一个.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.

或者仅使用.split()函数在Java中并解析了CSV进入阵列和阵列装入的.xls与POI。

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天全站免登陆