Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening excel files from the internet opens a blank excel window

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.

like image 859
Taylor Brown Avatar asked Jul 19 '16 15:07

Taylor Brown


People also ask

Why does Excel open a blank window when I open a File?

Option 1: Check for hidden sheets An Excel sheet may inadvertently have been saved as a hidden document. To check this, follow these steps: Go to the View tab. Select Unhide.

How do I stop Excel from opening a blank workbook when I open an existing File Mac?

Stop a specific workbook from opening when you start Excel Note: For more information about locating the startup folder, see Locate the XLStart folder. Click File > Options > Advanced. Under General, clear the contents of the At startup, open all files in box, and then click OK.


Video Answer


2 Answers

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)
like image 141
Taylor Brown Avatar answered Nov 03 '22 02:11

Taylor Brown


Solution 3

  • Go into the properties of the file (R click - properties)
  • Click 'Unblock'
  • Click 'Apply'
like image 40
Josh Bucklen Avatar answered Nov 03 '22 02:11

Josh Bucklen