Opening excel files from the internet opens a blank excel window
Solution 1
Solution 1
1) Open Excel Go to File Options
2) Click Trust Center -> Trust Center Settings
3) Go to Protected View. there are 3 options that show that were all clicked. Uncheck the first option that reads -- "Enable Protected View for files originating from the Internet". In some cases as reported in the comments below both the 1st and 2nd options need to be unchecked (Thanks @mosheb)
Solution 2
Uninstall these Windows Updates:
- Windows Update KB3115262 (Excel 2013)
- Windows Update KB3115130 (Excel 2010)
Solution 2
Solution 3
- Go into the properties of the file (R click - properties)
- Click 'Unblock'
- Click 'Apply'
Solution 3
changing the security options was unfortunately not an option, but it turns out that if you export to CSV instead of XLS then the file will open in Excel ignoring the trust center stuff.
We're in Classic ASP, so we change the page from exporting an HTML table format to CSV and changed our header and contenttype to this:
Response.AddHeader "content-disposition", "attachment; filename=search_results.csv"
Response.ContentType = "text/csv"
and did line breaks with: Response.Write (chr(10))
Solution 4
Try doing following:
Replace "attachment" from
Response.AddHeader("content-disposition","attachment;filename=GridViewExport.xls")
with "inline"
Response.AddHeader("content-disposition","inline;filename=GridViewExport.xls")
It may help!
Content-Disposition:What are the differences between "inline" and "attachment"?
Solution 5
Just thought I'd mention there is a third solution:
Add the site generating the .xls to your Trusted Sites list. I had to add about a dozen websites via GPO, because our CIO is refusing to roll back the KB... =(
Taylor Brown
full stack software engineer for intelligence pursuit inc. - jericho, new york
Updated on June 19, 2022Comments
-
Taylor Brown almost 2 years
A method in dumping a GridView to an Excel file to download/open from the internet was recently broken with new Windows Updates.
My code dumps from a GridView to an XLS file using StringWriter, HTMLTextWriter and RenderControl. A common approach using the following code from http://www.aspsnippets.com/Articles/Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx
Protected Sub ExportToExcel(sender As Object, e As EventArgs) Response.Clear() Response.Buffer = True Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls") Response.Charset = "" Response.ContentType = "application/vnd.ms-excel" Using sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) 'To Export all pages GridView1.AllowPaging = False Me.BindGrid() GridView1.HeaderRow.BackColor = Color.White For Each cell As TableCell In GridView1.HeaderRow.Cells cell.BackColor = GridView1.HeaderStyle.BackColor Next For Each row As GridViewRow In GridView1.Rows row.BackColor = Color.White For Each cell As TableCell In row.Cells If row.RowIndex Mod 2 = 0 Then cell.BackColor = GridView1.AlternatingRowStyle.BackColor Else cell.BackColor = GridView1.RowStyle.BackColor End If cell.CssClass = "textmode" Next Next GridView1.RenderControl(hw) 'style to format numbers to string Dim style As String = "<style> .textmode { } </style>" Response.Write(style) Response.Output.Write(sw.ToString()) Response.Flush() Response.[End]() End Using End Sub Public Overrides Sub VerifyRenderingInServerForm(control As Control) ' Verifies that the control is rendered End Sub
Excel (2013) will open to a blank window, with no warning or message as to why anything was blocked, and without option to accept the file to open.
My code is run on an intranet site, and I do have access to group policies / settings / user configurations in Windows.
-
Taylor Brown almost 8 yearsThe code in the question does apply some formatting (setting backcolor) but for your requirements, and probably many others, this is a great solution as well. I am sure I have a few places where I can apply this (companies outside of our intranet where we can't just uninstall windows updates etc.) Thank you!
-
Paul almost 8 yearsAs with the accepted solution, this can only be applied by the user at the request end of the pipe. I don't really see this as a solution.
-
Paul almost 8 yearsThis can only be applied by the user at the other end of the pipe, and not everyone will be willing to take this approach. To me, this is a one off workaround and not a solution.
-
Taylor Brown almost 8 years@Paul Honestly the only true solution I have found is to not use this block of code anymore. If anyone can alter this code and make it work I will accept that answer instead.
-
Taylor Brown almost 8 years@paul I submitted this as Q/A style to answer my own question to share my knowledge. I have edited the question in an attempt to better describe what my situation was and the types of access I have over my users and code in the intranet environment this runs in. This has served as a solution for me given my situation.
-
clamum over 7 yearsHow did you change your page to output to .csv? As a test, I took an .xls that was outputted by my website, copied it, and renamed the extension to ".csv". Opening it showed all the HTML tags and it was messy looking. I'm looking at possibly using this .csv format as a solution to this blank Excel window problem when opening the document during export in Internet Explorer, but I'm unsure of how to change my existing Excel export to .csv and not have it look horrible.
-
Admin over 7 yearsNothing is being implemented by the end user, is is being set domain-wide through Group Policy
-
mosheb over 7 yearsWe had to uncheck the first AND the second to get this working on our intranet
-
Taylor Brown over 7 years@clamum I think you're right, just changing the content type output does not serve as a solution. I think there is quite a bit of code changes missing from this answer. Correct me if I am wrong.
-
clamum over 7 years@taybriz That was my conclusion after doing my little copy-paste-rename test before. Maybe the OP can hopefully update us. I gave my manager a couple options for updating our website to fix this issue and I advised him that we should rewrite the Excel export using the EPPlus open source library. It'll take me several days, estimated, but I think it'll fix it.
-
Mohammed Dawood Ansari over 7 yearsyou saved my day buddy :)
-
Mohammed Dawood Ansari over 7 yearsI tried it and I am getting "Unable to read file." from excel and same blank excel comes.
-
Denver over 7 yearsthank you for this. for the others this will save their time.
-
Taylor Brown over 7 yearsthis is not really an answer as much as a suggestion and it seems someone tried this suggestion and says it does not work.