Hi Yegor!
I' ve trought make working out this method (wich is similar to one of the
given examples we all know),
but the slightly diference is that i use OutputStream instead of
FileInputStream, and that's what make the incoming excel to be corrupted.
this is the worng code:
protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename=\"whatever.xls\"");
OutputStream out=response.getOutputStream();
Workbook wb = new SXSSFWorkbook(-1);
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 10000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
cell.setCellValue("dummy text");
}
if(rownum % 100 == 0) {
((SXSSFSheet)sh).flushRows(100);
}
}
wb.write(out);
out.close();
}
and this is the right code , these are the changes that i did in order
to
work it out. And it worked out! :)
protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename=\"whatever.xls\"");
Workbook wb = new SXSSFWorkbook(-1);
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 10000; rownum++){
Row row = sh.createRow(rownum);
for(int cellnum = 0; cellnum < 10; cellnum++){
Cell cell = row.createCell(cellnum);
cell.setCellValue("dummy text");
}
if(rownum % 100 == 0) {
((SXSSFSheet)sh).flushRows(100);
}
}
FileOutputStream out = new FileOutputStream("c:/whatever.xlsx");
wb.write(out);
out.close();
}
that means that with SXSSF we cannot work with outputstream and
response to
show the excel. The problem is that in this way the file is saved to disk.
then.
My final is question:
Should i try to read this xlsx after saving? or try to make work the
outputStream with response.
moreover, is there some way to read the xlsx i've saved to disk
Thanks in advance ;)
Ricuelo
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/problem-opening-excel-2007-created-using-SXSSF-tp4705693p4876799.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]