Murray Brown
asked on
ASP.net VB.net Create Excel file with sheet name "Sheet1"
Hi
I am using the following VB.net code on my ASP.net web form to populate an Excel spreadsheet
from a data table. At the moment the sheet name is derived from the SQL table that
the data table was pulled from. I need the sheet name to be "Sheet1". How do I do this
I am using the following VB.net code on my ASP.net web form to populate an Excel spreadsheet
from a data table. At the moment the sheet name is derived from the SQL table that
the data table was pulled from. I need the sheet name to be "Sheet1". How do I do this
Public Sub ExportToExcel_AsXlsFile(ByVal dt As DataTable, ByVal file_name As String)
Dim grid = New GridView()
grid.DataSource = dt
grid.DataBind()
Response.ClearContent()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment; filename='" & file_name & "'.xls")
Response.ContentType = "application/ms-excel"
Response.Charset = ""
Dim sw As System.IO.StringWriter = New System.IO.StringWriter()
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
grid.RenderControl(htw)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Sub
ASKER
Thanks. Is there not a simpler way to change the code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both very much
More info here:
https://archive.codeplex.com/?p=epplus