CSV产生可能与Apache POI? [英] CSV generation possible with Apache POI?

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

问题描述

我需要生成CSV文件,我偶然发现在我们的项目本身就是一个模块,使用Apache POI到已位于生成Excel表上。所以我想我可以使用相同的生成CSV。于是我问谷歌兄弟,但他无法找到肯定的东西,说的Apache POI可用于CSV文件的生成。我在下面的API检查过,它只有大约XLS张会谈,并没有在任何地方CSV文件。任何想法?

I need to generate csv files and I stumbled on a module in our project itself which uses Apache POI to generate excel sheets aleady. So I thought I could use the same to generate csv. So I asked google brother, but he couldnt find anything for sure that says Apache POI can be used for CSV file generation. I was checking on the following api too and it only talks about xls sheets and not csv anywhere. Any ideas?

http://poi.apache.org/ apidocs /组织/阿帕奇/ POI / SS /的usermodel / Workbook.html

推荐答案

阿帕奇浦二不会输出到CSV为您服务。但是,你有几个不错的选择,这取决于什么样的数据你正在写为CSV。

Apache Poi will not output to CSV for you. However, you have a couple good options, depending on what kind of data you are writing into the csv.

如果您知道不关你的细胞将包含CSV标记,如逗号,引号,行尾,那么你可以通过你的数据行循环和文本复制到一个StringBuffer和发送到常规的Java IO。
这里是沿着这些线路写一个SQL查询到CSV的例子:浦二通讯录:写CSV

If you know that none of your cells will contain csv markers such as commas, quotes, line endings, then you can loop through your data rows and copy the text into a StringBuffer and send that to regular java IO. Here is an example of writing an sql query to csv along those lines: Poi Mailing List: writing CSV

否则,而不是找出如何逃脱自己的特殊字符,你应该看看 opencsv项目

Otherwise, rather than figure out how to escape the special characters yourself, you should check out the opencsv project

这篇关于CSV产生可能与Apache POI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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