|
-
February 13th, 2009, 05:41 AM
#1
Export datatable to excel file
Hello gurus!
I use the following code (see bottom of post) to create a native xls file, with Microsoft Office 2007 installed. However, when I open the file there's always a warning telling me:
"The file you are trying to open, 'file.xls' is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening this file. Do you want to open the file now?"
When clicking "Yes" the file opens just fine.
My question is: How can I get rid of this warning? It is obviously not corrupted, and the datatable contains no special characters. I don't see how the format is related to "trusted source", whatever that means. Can someone please explain?
Code:
Protected Sub ExportAsExcelFile(ByVal dtExport As DataTable)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Dim objStringWriter As New System.IO.StringWriter
Dim objHtmlTextWriter As New System.Web.UI.HtmlTextWriter(objStringWriter)
Dim objDatagrid As New DataGrid
objDatagrid.DataSource = dtExport
objDatagrid.DataBind()
objDatagrid.RenderControl(objHtmlTextWriter)
Response.Write(objStringWriter.ToString())
Response.End()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|