CSV generation possible with Apache POI?

前端 未结 3 1709
礼貌的吻别
礼貌的吻别 2020-12-06 07:49

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 gen

3条回答
  •  广开言路
    2020-12-06 08:24

    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.

    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

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

提交回复
热议问题