• Post Reply Bookmark Topic Watch Topic
  • New Topic

open excel file  RSS feed

 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I open the existing xsl file in JSP page or java?

I have done like this, but I don't see the contents of the ATR.xls. This file is located in C: drive.



response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment; filename= c:\\ATR.xls");


Can anyone tell what is the wrong in this code please?

Thanks
[ March 07, 2008: Message edited by: lakshmi manepally ]
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lakshmi,

The response.setHeader(..) doesn't do what you think it does. It does not attach the file to your response. It merely gives a name to your response.
You can read more about this here.

So additionally, you will have to read the excel file content, and stream that content to your response.

Best to do it with a Servlet. A jsp will add additional content to your stream - and that spoils the output.

Regards, Jan

(There is a separate JSP and Servlets forum on the Ranch)
 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want only in jsp
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by lakshmi manepally:
I want only in jsp

Ok. Please read Stefan Evans' remark, the latest post on 29 november 2007 in this thread.

Regards, Jan
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by lakshmi manepally:
I want only in jsp

Why? This makes your task significantly harder. Is there a reason for the JSP only requirement?
 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have gone through this program.
CODE]

try{
String ROOT_PATH = "C:\\tomcat\\webapps\\SnetReport\\REPORT\\"; FileInputStream in = new FileInputStream(ROOT_PATH + sFilename);
response.setContentType("application/xls"); response.setHeader("Content-Disposition", "attachment;filename=\"Report.xls\"");

int i; while ((i=in.read()) != -1)
{ out.write(i); }
in.close();
out.close();}catch(Exception e)

System.out.println("...error while loading: "+e.toString());}
[/CODE]

In the above code what is the sFileName
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!