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?
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.
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.
Joined: Mar 22, 2005
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.
Joined: Oct 08, 2006
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.