poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Abe Mishler <...@mishlerlabs.com>
Subject Malformed xls with struts2 and POI 3.5-beta6
Date Fri, 24 Jul 2009 20:37:56 GMT
Hi all,

I need some pointers/help with creating an .xls file for download from a 
servlet container.

Specifically, I have a struts2 project running inside Tomcat 5.5. And 
I'm using POI 3.5-beta6.

I am able to use POI to create a workbook and fill it with data. The 
problem is after I download the file, the binary header doesn't match 
the expected: D0 CF 11 E0 A1 B1 1A E1 signature.

Instead, I get: 09 08 10 00 00 06 05 00 D3 10 CC 07 41 ...

I'm definitely getting a binary file. When I open the file using MS 
Excel 2003 SP2, it goes into file recovery mode telling me the file is 
damaged beyond repair, etc. After I click "Don't Send" a couple times on 
the error dialogs, my data is there, although without the formatting 
(Date values look like numbers).

I have one immediate concern: All of the examples use wb.write(fileOut), 
however, AFAIK, that's not the way for writing data out of a servlet 
container for download. I'm familiar with creating an InputStream for a 
file download.

I've included a basic execute() method from my action which demonstrates 
how I export the data to the user for download. Is this causing the 
malformed file? How do I get the workbook bytes[] into an InputStream 
properly?

Thanks in advance,
Abe

==

I have an action class with an execute() method as follows:

public String execute() throws Exception {
	Workbook workbook = new HSSFWorkbook();
	Sheet s = workbook.createSheet("sheet");
	Row r = s.createRow(0);
	Cell c = r.createCell(0);
	c.setCellValue("hello world");
	ByteArrayInputStream bais =
		new ByteArrayInputStream(
		((HSSFWorkbook) workbook).getBytes());
	inputStream = bais;
	return SUCCESS;
}

and the necessary getter for inputStream.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message