Recently i was working on a task to export my reports in excel format, i found that my exported excel sheets are not opening in new browser window or in excel window , they are opening in the same page itself where i clicked the button to export data to excel sheet. I Googled the problem, i didn’t find any promising solution at all. Later i tried the same functionality in my friend’s machine there it’s working fine. Then i thought there was some thing with settings of the client machine which are making my excel to open in the same window Here is the setting which made my Exported excel sheet to open in the same browser window.

Folder Options – > File Types –> XLS ( excel file type) –> Advanced
When i uncheck the option ‘Browse in Same window’ it’s working for me. Later i found that MS office 2003 have this setting checked where as MS office 2007 has this option unchecked by default.
But it’s not a great idea to ask client to change their settings, as a developer we have to find some workaround for it, so then i came with the following solution which will work irrespective of the client settings.
Workaround for opening Exported Excel sheet in New browser Window
The idea is to create a new aspx page and then write your code in that new window. So when user click on ‘Export Excel Button’ it will trigger new page opening code and there it will process our ‘Exporting Data to Excel’. Here you may have two scenario’s,
1. Get the data again from Data source
In this case you create a new page and open that page when user click on ‘Export Excel button’ , internally there you will get your data from data source and then you will process that data and then finally you export that data table or data grid to Excel sheet.
function openExcelPage()
{
window.open("ExcelReport.aspx","ExcelReport",
"toolbar=yes,menubar=yes,location=yes,status=yes,location=yes,
height=600,width=800,scrollbars=yes,resizable=yes",false);
}
2. Cache the data in this page and use this data in the new page.
This case will be useful when you have data already exits in grid or data table which need to be exported to the excel sheet, as getting this data again is a costly operation , you can avoid that by caching the data in memory then retrieve that cache in the newly created page and then do the ‘Export Data Table to Excel sheet’ coding in the new page.
function openExcelPage(key)
{
window.open("ExcelReport.aspx?key=" + key,"ExcelReport",
"toolbar=yes,menubar=yes,location=yes,status=yes,location=yes,
height=600,width=800,scrollbars=yes, resizable=yes",false);
}
Here i am sending the string key to new page ( key is the cache pointer).
I hope i am clear with the above two scenario’s, if you have any other way of doing it let us know.