Открытие файлов Excel из Интернета открывает пустое окно Excel

Метод выгрузки GridView в файл Excel для загрузки / открытия из Интернета недавно был поврежден новыми обновлениями Windows.

Мой код дамп из GridView в файл XLS, используя StringWriter, HTMLTextWriter и RenderControl. Общий подход с использованием следующего кода из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) откроется в пустом окне без предупреждения или сообщения о том, почему что-либо было заблокировано, и без возможности принять файл для открытия.

Мой код выполняется на сайте интрасети, и у меня есть доступ к групповым политикам / настройкам / пользовательским конфигурациям в Windows.

Ответы на вопрос(7)

Ваш ответ на вопрос