This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Opening an xlsx Excel file" Watch "Opening an xlsx Excel file" New topic
Author

Opening an xlsx Excel file

gendhe ranjith kumar
Greenhorn

Joined: Mar 28, 2011
Posts: 20
hi

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);
}

fileIn.close();
outExcel.flush();
outExcel.close();

%>



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

Ranjith
Ulf Dittmer
Marshal

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


Ping & DNS - my free Android networking tools app
gendhe ranjith kumar
Greenhorn

Joined: Mar 28, 2011
Posts: 20
hi

thanks for your response.

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

it is fails in excel 2007.

thanks & regards

Ranjith.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
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
Problem on opening .XLSX file
xlsx file name problem in internet explorer
displaying jsp filename to downloading file in internet explorer
Forwarding after response committed
problems in downloading epub files