tags:

views:

378

answers:

3

Hello, I’m looking for a – simple – solution to output big excel files. Input data comes from the database and I’d like to output the Excel file directly to disk to keep memory consumption as low as possible. I had a look to things like Apache POI or jxls but found no way to solve my problem.

And as additional information I need to generate .xls files for pre 2007 Excel, not the new .xlsx xml format. I also know I could generate CSV files but I’d prefer to generate plain Excel…

Any ideas ?

I realize my question isn't so clear, I really want to be able to write the excel file without having to keep the whole in memory...

+2  A: 

No idea for generating a real XSL file. But you can directly write a HTML file, or a zip stream containing an OPenDocument spreadsheet (I guess MSExcel can read this later format)

Pierre
HTML is an extremely bad idea. Don't do that. Excel will messup it on edit/save and the latest versions will complain about unsupported file format. Use XLS/XLSX/CSV only.
BalusC
+2  A: 

JExcelAPI is often recommended as a more memory efficient alternative to Apache POI.

Brian Agnew
+2  A: 

The only way to do this efficiently is to use character-based CSV or XML (XLSX) format, because they can be written to the output line by line so that you can per saldo have only one line at once in the memory all the time. The binary-based XLS format must first be populated completely in memory before it can be written to the output and this is of course memory hogging in case of large amount of records.

I would recommend using CSV for this as it may be more efficient than XML, plus you have the advantage that the any decent database server has export capabilities for that, so that you don't need to program/include anything new in Java. I don't know which DB you're using, but if it were for example MySQL, then you could have used LOAD DATA INFILE for this.

BalusC
Thanks for your answer, I think I will go for CSV till my company migrates to a newer Office version and then continue with xlsx. You know about a library to generate xlsx line by line ?
pgras