Hello again Luke,

The code can indeed be very simple if your requirement is also quite
straightforward. If all you want to do is to extract the contents of each
cell as a string, format it so that it resembles what you would see when
viewing the sheet with Excel and then write it away to the CSV file, this
can be accomplished with just a few lines of code. All you would need to do
is something like this;

Open the workbook.
Recover the number of sheets in the workbook.
Iterate through the sheets and for each;
    Get the number of rows.
    Iterate through the rows on the sheet and for each;
        Get the number of cells;
        Iterate through cells on the row and for each
            Use the DataFormatter class to return a formatted String
describing the cell's contents
            Write that String away to the CSV files line.

Of course there are a few wrinkles, what to do with empty cells or cells
that are simply missing from the row but there are a couple of techniques to
help with this. If I have the time a little later today, I will put together
some code that will do the above. Unlike the example I pointed out to you
yesterday, I will focus on what is termed the usermodel and, more precisely,
the classes in the so called 'SS' package. Whilst this is a little more
abstract, it will allow you to use the same code to process either older
binary files (.xls) and newer xml ones (xlsx); POI determines which it is
dealing with and creates the appropriate concrete classes.

Yours

Mark B


Luke_Devon wrote:
> 
> Hi Mark,
> 
> First of all I would like to thank you for the reply. 
> 
> Actually , currently I am using MS Office 2002. But I would like to use
> the code for other latest versions also.
> In my case , I dont want to do any validations for the EXCEL file ,
> because I just wanted convert entire excel file into CSV.
> Is there any simple java code available for such a basic requirement ?
> 
> anyway I'll try to use the code in the link which you have given to me .
> 
> Thanks & Regards
> 
> Luke.
> 
> 
> 
> 
> ________________________________
> From: MSB <[email protected]>
> To: [email protected]
> Sent: Thursday, April 8, 2010 23:47:07
> Subject: Re: Convert XLS into CSV
> 
> 
> Hello Luke,
> 
> Which version of the Excel file format are you targetting, the older
> binary
> or newer xml based version? I ask because Nick wrote and contributed some
> code that can be used to convert the older binary files into csv. It uses
> the eventmodel and will seem quite complex on first acquaintance but here
> it
> is;
> 
> http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/hssf/eventusermodel/examples/XLS2CSVmra.java
> 
> I know that other users have modified the code to, for example, output
> diffenert worksheets to separate csv files.
> 
> Yours
> 
> Mark B
> 
> 
> Luke_Devon wrote:
>> 
>> Hi 
>> 
>> I wanted to convert some XLS files into CSV. I found that apache.poi is
>> the most perfect tool. Since I'm a beginner , i have no idea how to do
>> that . Can some body help me please ? Do you have sample code for convert
>> xls into csv ?
>> 
>> Thanks in Advance
>> Luke
>> 
>> 
>> 
>>       Get your preferred Email name!
>> Now you can @ymail.com and @rocketmail.com. 
>> http://mail.promotions.yahoo.com/newdomains/aa/
>> 
> 
> -- 
> View this message in context:
> http://old.nabble.com/Convert-XLS-into-CSV-tp28175999p28180503.html
> Sent from the POI - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
>       New Email names for you! 
> Get the Email name you&#39;ve always wanted on the new @ymail and
> @rocketmail. 
> Hurry before someone else does!
> http://mail.promotions.yahoo.com/newdomains/aa/
> 

-- 
View this message in context: 
http://old.nabble.com/Convert-XLS-into-CSV-tp28175999p28188192.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to