vrijdag 18 mei 2007

excel export from webapp HSSF IE

While using the spring-framework (rocks!) I used the poi framework of jakarta to generate excel sheets. All went well in firefox but when I tried this with Internet Explorer the file was broken. The application opening it couldn't find the temp file.

My solution for this is in using the correct response headers. I found these by looking at an opensource project with excel export functionality (thx 2 phpMyAdmin).

Using the following headers works for me:

//control cache, these make the difference
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "Public");
//these are xls specific
response.setHeader("Content-Disposition", "attachment; filename=action.xls");
response.setHeader("Content-Type", "application/vnd.ms-excel");

So good luck with it, also check your filename for characters not allowed by your filesystem.

Geen opmerkingen:

Een reactie plaatsen