Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

open excel file  RSS feed

 
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 ]
 
Bartender
Posts: 2633
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: 2633
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
 
author & internet detective
Marshal
Posts: 38367
645
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
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!