wood burning stoves 2.0*
The moose likes JSP and the fly likes Opening an xlsx Excel file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Opening an xlsx Excel file" Watch "Opening an xlsx Excel file" New topic

Opening an xlsx Excel file

gendhe ranjith kumar

Joined: Mar 28, 2011
Posts: 20

i am using the following code to download xlsx file from server.

String resultXLS="file downloading from jsp.xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
response.setHeader("content-disposition", "attachment; filename=\"" + resultXLS + "\"");

File file = new File(filepath);
FileInputStream fileIn = new FileInputStream(file);
OutputStream outExcel = response.getOutputStream();

byte[] outputByte = new byte[8192];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 8192) != -1)
outExcel.write(outputByte, 0, 8192);



the file generated. but i am getting some error messages.

1."excel found unreadable content. do you want to recover from it".

2."the file cannot opened by Microsoft excel . do you want to search on online for converter to open the file".

any help on this will be appreciated.

Thanks & regards

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39547
You can't handle binary data with JSPs; you need to write a servlet instead.

Ping & DNS - updated with new look and Ping home screen widget
gendhe ranjith kumar

Joined: Mar 28, 2011
Posts: 20

thanks for your response.

the above code is working fine in case of 2003 excel.

it is fails in excel 2007.

thanks & regards

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39547
Then you got lucky (and the old Excel file format may be more forgiving than the new one). But I repeat: using JSPs to handle binary data will fail eventually. You're better off getting it right from the start than to suffer later.
I agree. Here's the link: http://aspose.com/file-tools
subject: Opening an xlsx Excel file
Similar Threads
Forwarding after response committed
displaying jsp filename to downloading file in internet explorer
problems in downloading epub files
Problem on opening .XLSX file
xlsx file name problem in internet explorer