Exported Excel sheet is not opening in IE new window?

  • Share/Save/Bookmark

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.

xlsSettings

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.

Categories : C#, Javascript

Leave a Reply

About Techieon

Techieon is all about sharing Development experience of experienced talented developers of different technologies working in real time. Here at Techieon we talk about latest updates of different technologies, provide solutions to the developers problems, write tutorials on frequently used tools of development and provide tips to developers day to day activities.

This is a Widget Section

This section is widgetized. If you would like to add content to this section, you may do so by using the Widgets panel from within your WordPress Admin Dashboard. This Widget Section is called "Feature Bottom Middle"

Want to Write for Techieon?

Techieon have few opening positions for talented developers who want to share their development experience with Techieon users.If you are interested in writing at Techieon please Contact us or e-mail me for more information.