P
postings
Hi
Could you possibly look at the code below that exports a datagrid to
Excel in ASP.NET?
It works fine, but characters such as quotes come out garbled.
i.e. "Fred's House" will come out in the spreadsheet as "Fred’s
House".
Could you give me any pointers here? Is it the character set or
something.
Many thanks
Alex
----->
'Note DGContacts is a datagrid
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
DGContacts.AllowSorting = False
DGContacts.AllowPaging = False
DGContacts.Columns.Remove(DGContacts.Columns(0))
Call populatedatagrid()
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
DGContacts.RenderControl(hw)
' Write the HTML back to the browser.
Dim strFileName As String = "products.xls"
Response.Clear()
Response.Buffer = True
Response.Expires = 0
' Change the HTTP header to reflect that an image is being passed.
Response.AddHeader("Content-Disposition", "attachment; filename=" &
strFileName)
Response.Flush()
Response.Write(tw.ToString())
Response.End()
<-----
Could you possibly look at the code below that exports a datagrid to
Excel in ASP.NET?
It works fine, but characters such as quotes come out garbled.
i.e. "Fred's House" will come out in the spreadsheet as "Fred’s
House".
Could you give me any pointers here? Is it the character set or
something.
Many thanks
Alex
----->
'Note DGContacts is a datagrid
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
DGContacts.AllowSorting = False
DGContacts.AllowPaging = False
DGContacts.Columns.Remove(DGContacts.Columns(0))
Call populatedatagrid()
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
DGContacts.RenderControl(hw)
' Write the HTML back to the browser.
Dim strFileName As String = "products.xls"
Response.Clear()
Response.Buffer = True
Response.Expires = 0
' Change the HTTP header to reflect that an image is being passed.
Response.AddHeader("Content-Disposition", "attachment; filename=" &
strFileName)
Response.Flush()
Response.Write(tw.ToString())
Response.End()
<-----