Hello,
I have the code below that creates an excel file from a datatable, but I do not want it to open. I just want to save the file. Is there anyway to do that?
Protected Sub ExportDataTableToExcel(ByVal dt As System.Data.DataTable, ByVal strFileName As String)
Dim strAddHeader As String
Dim gv As GridView
gv = New GridView
gv.AllowPaging = False
gv.DataSource = dt
gv.DataBind()
strAddHeader = "attachment;filename=" & strFileName
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", strAddHeader)
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
For i As Integer = 0 To gv.Rows.Count - 1
'Apply text style to each Row
gv.Rows(i).Attributes.Add("class", "textmode")
Next
gv.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode{mso-number-format:\@;}</style>"
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.End()
End Sub
Thanks for your help in advance.
Eddi Rae