Ciao a tutti, ho un problema con un export in excel. Di seguito il codice:
codice:
response.Clear()
response.Charset = ""
response.ContentType = "application/vnd.xls"
response.AddHeader("Content-Disposition", "attachment;filename=" & nomeExport.Replace(" ", "_") & "_" & String.Format("{0:yyyyddMMhhmmss}", DateTime.Now) & ".xls")
response.ContentEncoding = System.Text.Encoding.UTF8
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
htmlWrite.Write("<table><td colspan=""" & Tbl.Columns.Count & """><h2>" & nomeExport & " (" & Format(Date.Now(), "dd/MM/yyyy") & ") Operatore: " & SicOperatore.OperatoreValidatoUsername & "</h2></td></table>")
'instantiate a datagrid
Dim dg As New System.Web.UI.WebControls.DataGrid
dg.DataSource = Tbl
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)
Audit.Registra(nomeExport & " in Excel")
response.End()
Quando si apre Excel non si carica niente resta una pagina vuota.