File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Opening XL sheet in a URL in ms excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Opening XL sheet in a URL in ms excel" Watch "Opening XL sheet in a URL in ms excel" New topic
Author

Opening XL sheet in a URL in ms excel

Ranjeeth Chandra
Greenhorn

Joined: Sep 19, 2008
Posts: 7
Hi all,

Consider I have a URL - http://someurl/file.xls

I need to do a response.sendRedirect(url) into this url. This opens the file in the browser itself. But I need to open it in microsoft excel.

Normally we have a the content of the excel file (html table format)
then we do response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=data.xls");
outwriter.writeln(html table content);

this gives us the content in an ms excel window rather than browser. Instead of attachment above if we say inline, it'll open the contents in the browser itself but will look like excel but goofier.

The content when too large can't be manipulated on the server due to memory issues so I want to do have the file in a url link and do sendRedirect, but open it in msexcel itself.

Is it possible? Could anyone please help me in solving this?

Thanks
Ranji


Thanks,
Ranji
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Ranjeeth Chandra wrote:Hi all,
The content when too large can't be manipulated on the server due to memory issues
If you buffer the streams you don't need to worry about it.
How to buffer the streams is covered by every decent Java IO tutorial.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
Whether a particular file type will be opened in the browser or in a special application like Excel is a browser setting that each user can set on their own. E.g., in Firefox, look at Preferences -> Applications.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I wouldn't ask every client to do so, so that the original code just works. To open a file in an external application, the only reliable way is to set content disposition to attachment. And that's not possible with a sendredirect as it creates a brand new request and thus also a brand new response -where you don't have control over.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
To open a file in an external application, the only reliable way is to set content disposition to attachment.

Yes. But that's not sufficient if the browser is set to open the file using the plugin.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
To my experience, that applies to responses with content-disposition=inline only.

When content-disposition=attachment, the client will be asked to open or save the file. In the 'open' option, always the external application is selected by default, regardless of the default setting for inline requests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Opening XL sheet in a URL in ms excel