tags:

views:

31

answers:

0

Hi All,

I am writing jsp to export data in excel format to user. I could succeed in returning an excel to the cient side. However, since there's large amount of data, I don't want to keep it in the server memory and write them at the end. Therefore, I try to divide them and write to the output stream separately through calling the response.getOutputStream().write serveral times.

However, each write(..) will cause an extra new lines inserted at the top of the data in the excel worksheet.

For example if I called response.getOutputStream().write(xxxx) 2 times, then the result will be like this:

(empty line) (empty line) data line 1 data line 2

Does anyone know the reasons?

The code is something like this:

response.setHeader("Content-disposition","attachment;filename=DocuShareSearch.xls");
response.setHeader("Content-Type", "application/octet-stream"); 

responseContent ="<table><tr><td>12131</td></tr>.......";
byte[] responseByte1 = responseContent.getBytes("utf-16");
outputStream.write(responseByte1, 0, responseByte1.length ); 

responseContent =".....<tr><td>12131</td></tr></table>";
byte[] responseByte2 = responseContent.getBytes("utf-16");
outputStream.write(responseByte2, 0, responseByte2.length ); 

outputStream.close();