views:

616

answers:

2

Hi all.

I have an Excel 2007 xlsx file that I would like to programmatically convert to an .xls file. The xlsx file is an export from a reporting tool, and I would like to convert it to xls for better compatibility with the software stack of my application users. The xlsx is as plain as it gets. Just rows with data and basic type information (int/date/string). No formulas.

My platform is Java, and I do not have Microsoft Office installed. I'm looking for a solution that will allow me to convert between the formats with the least amount of effort. I.e. I'd like to avoid having to write a custom "copy application" that would read the xlsx file and copy the rows and formatting to another file. Preferably, the solution is open source and/or free.

I have looked at POI, and as far as I could tell, it can read and write both xls and xlsx files. But I was not able to tell by browsing the documentation and examples if it could read one format and write out in the other. Before I dig in any deeper, I would like to check if any of you out there have done anything like this before in Java, and if you have any tips.

Hope to hear back from you!

Regards Bent

A: 

I don't see any reason why you can't convert from one format to another. POI holds a model of the document in memory, so you should be able to read one in, and write another out with little grief. You'll have to hold the complete document in memory and POI has a reputation for being memory hungry, so that may be an issue to consider.

Brian Agnew
It is a reasonable assumption, but all the examples show a WorkBook object being created ( Workbook wb = new HSSFWorkbook(); ), and then written ( wb.write(out); ). So the WorkBook object is responsible for writing itself to an OutputStream, and there is an implementation of WorkBook for both the xls and xlsx format. I don't see how direct conversion is possible with this api.
Bent André Solheim
A: 

You can try SmartXLS for java.

It support most excel features in both xls and xlsx formats.

liya
Yes, I checked it out, but it has a price tag. I'd prefer a free solution, but I just might have to open my wallet.
Bent André Solheim