Murray Brown
asked on
ASP.net File format issue in producing Excel file
Hi
I am using the VB.net code below produce an Excel file from a data table in my ASP.net web app. I get the following message
when opening the Excel file in Excel 2007. Surely Excel 2007 should recognize .xls as an Excel 97 to 2003 file.
Is there a way to stop this message coming up? Can this code be improved?
I am using the VB.net code below produce an Excel file from a data table in my ASP.net web app. I get the following message
when opening the Excel file in Excel 2007. Surely Excel 2007 should recognize .xls as an Excel 97 to 2003 file.
Is there a way to stop this message coming up? Can this code be improved?
Public Sub CreateExcelFile(Excel As DataTable)
'http://www.c-sharpcorner.com/UploadFile/0c1bb2/create-excel-file-from-database-using-Asp-Net-C-Sharp/
'Clears all content output from the buffer stream.
Response.ClearContent()
'Adds HTTP header to the output stream
Response.AddHeader("content-disposition", String.Format("attachment; filename=MyExcelDowbload.xls"))
' Gets or sets the HTTP MIME type of the output stream
Response.ContentType = "application/vnd.ms-excel"
Dim space As String = ""
For Each dcolumn As DataColumn In Excel.Columns
Response.Write(space + dcolumn.ColumnName)
space = vbTab
Next
Response.Write(vbLf)
Dim countcolumn As Integer
For Each dr As DataRow In Excel.Rows
space = ""
For countcolumn = 0 To Excel.Columns.Count - 1
Response.Write(space & dr(countcolumn).ToString())
space = vbTab
Next
Response.Write(vbLf)
Next
Response.[End]()
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER