Webapp generated Excel Spreadsheet opens in same browser window – IE6

March 8, 2010

Hello,

While working on a web application that generates Excel spreadsheets , I faced the issue mentioned below.

Issue:

Sometimes the spreadsheet is opened up in a new MS-Excel application window and often opened in the same browser window.  This is used to happen for Internet Explorer 6.0. On IE7 it was not reproducible i.e. used to open up in the MS-Excel application all the time leaving browser intact.

Additional Information:

I had implemented this spreadsheet generation as below –

  1. Generate the spreadsheet using Apache POI.
  2. Set header content-type to “application/vnd.ms-excel“.
  3. In addition to content-type, I was also adding the header “Content-disposition” that assigns a filename to the content written on the response stream. Some excel files were named like “xyz/abc.xls“.
  4. Write the bytes on the Response stream.

Resolution:

We could figure out the behavior because when we ran the application and try to retrieve the report,

  1. For spreadsheets with filenames that did not contain “/” displayed the browser File Download dialog properly with “filename.xls”.
      ie6-saveas-noslash
  2. Whereas if the filename contained “/” in it then the File Download dialog shows
  • EITHER the URL that is used to retrieve the excel report from server. e.g. if you have a ReportServlet that serves the excel report then it would show “ReportServlet” instead of filename.
  • OR some random filename as shown below

ie6-filedownload

Once we fixed the filename generation logic to replace “/” with “-“(or any other valid character), reports started opening up in MS-Excel application than in same browser window.

Another thing to note here is that IE7 handles it internally by replacing “/” with “_” as shown below.

IE7-File Download Dialog

Note:

In addition to this while searching I found out the Microsoft knowledge-base which mentioned this issue can be resolved by doing some client side settings. This knowledge-base can be found at KB-162059.

Cheers !

Amit