hi i am trying to export gridview data in xlsx file using below code, but when i open file its showing error,
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx")
Response.Charset = ""
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
For Each r As GridViewRow In GridView1.Rows
If r.RowType = DataControlRowType.DataRow Then
For columnIndex As Integer = 0 To r.Cells.Count - 1
r.Cells(columnIndex).Attributes.Add("class", "text")
Next
End If
Next
GridView1.RenderControl(htmlWrite)
Dim style As String = "<style> .text { mso-number-format:\@; } "
Response.Write(style)
Response.Write(stringWrite.ToString())
Response.[End]()

Salman BegRank #284 · 8.8K reputationPosted Nov 14, 2019, 6:39 PM EST
Senorita124 reputationPosted Nov 14, 2019, 6:46 PM EST
Salman BegRank #284 · 8.8K reputationPosted Nov 15, 2019, 3:20 AM EST
Leon DRank #851 · 2.6K reputationPosted Nov 17, 2019, 7:00 PM EST
Senorita124 reputationPosted Nov 26, 2019, 10:29 PM EST
Senorita124 reputationPosted Nov 26, 2019, 10:46 PM EST
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 26, 2019, 11:25 PM EST