Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open excel in JSP

 
Rakesh Gadre
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to display an excel file to the user. In the jsp file, the code is as under:

FileInputStream fileStream = new FileInputStream (fileNameWithPath);
int numberOfBytes = fileStream.available ();
byte contents [] = new byte [numberOfBytes];
fileStream.read (contents);
ServletOutputStream sout = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","inline; filename=\"" + onlyFileName + "\";");

sout.write (contents);

Now, the problem is as under:

The server does not have MS office(Excel) installed on it. If I try to set the content type as ms-excel, it does not recognises it and what i get is junk code. Is there any way to read the excel without having MS office(Excel) installed on the server ?

Thanks in advance

Rakesh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't bother trying to stream it through your servlet. Just add a link to it in a page and when the user clicks on the link whatever their browser/OS is configured to do with .xls files will happen.
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
I am trying to do something similar.

I have a JSP page which gets data from the DB.
I need to display the returned data displayed in an Excel sheet.
Have put the following code at the start of the JSP page.
<%@ page contentType = "application/vnd.ms-excel" %>
<% response.setContentType("application/vnd.ms-excel"); %>


It does open the excel sheet , but the sheet is empty.
There is no data.

Please guide.

Thanks,
Sahil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic