XLS to CSV source

View: New views
2 Messages — Rating Filter:   Alert me  

XLS to CSV source

by peterconn :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
This forum has provided great help in allowing me to create a XLSX2SV class for converting the newer XLSX document format to CSV format using the source provided by Yegor at

http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

I would also like to create a similar class for the older XLS format.
I did find source for the XLS2CSVmra class created by Nick Burch for which I noted that Chris Lott was awaiting a bug fix. Can someone point me to the most recent version of this or another XLS2CSV class that will convert the older XLS format to CSV.

Cheers, Peter

Re: XLS to CSV source

by MSB :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Peter,

You may be aware of this so forgive me please if I am repeating information you already know. The eventusermodel is typically but not exclusivly used to process very large files where memory restrictions often cause Java to crash. If your file is relatively small, you can very easily write a class that will output the contents to a CSV file. In psuedo code all you would need to do is the following;

Open the file Excel file.
Open the CSV file.
Get the number of sheets.
Iterate through the sheets and for each.
   Get a row iterator from the sheet and for each row.
      Get a cell iterator from the row and for each cell.
         Start a new line in the CSV file.
         Get the cell and call the HSSFDataFormatter classes formatCellValue() method. This
         returns a String formatted as the cells contents would be seen be someone using
         Excel.
         Write the String away to a line of the CSV file.

Obviously, this is a simplefied explanation, how you handlle missing rows/cells for example is something that you will have to decide upon of course.

Yours

Mark B

There may even be some code submitted by a list user if you have a search through the messages.
peterconn wrote:
Hi,
This forum has provided great help in allowing me to create a XLSX2SV class for converting the newer XLSX document format to CSV format using the source provided by Yegor at

http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

I would also like to create a similar class for the older XLS format.
I did find source for the XLS2CSVmra class created by Nick Burch for which I noted that Chris Lott was awaiting a bug fix. Can someone point me to the most recent version of this or another XLS2CSV class that will convert the older XLS format to CSV.

Cheers, Peter