Abrir arquivos do Excel a partir da Internet abre uma janela em branco do Excel
Um método para despejar um GridView em um arquivo do Excel para baixar / abrir da Internet foi recentemente quebrado com as novas atualizações do Windows.
Meu código despeja de um GridView para um arquivo XLS usando StringWriter, HTMLTextWriter e RenderControl. Uma abordagem comum usando o seguinte código dehttp://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
O Excel (2013) será aberto em uma janela em branco, sem aviso ou mensagem sobre o motivo pelo qual algo foi bloqueado e sem a opção de aceitar o arquivo para abrir.
Meu código é executado em um site da intranet e tenho acesso a diretivas / configurações / configurações de usuário do grupo no Windows.