Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dodgy Characters Exporting to Excel

Reply
Thread Tools

Dodgy Characters Exporting to Excel

 
 
postings@alexshirley.com
Guest
Posts: n/a
 
      09-26-2005
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()

<-----

 
Reply With Quote
 
 
 
 
postings@alexshirley.com
Guest
Posts: n/a
 
      09-26-2005
In reference to last post and just in case it is not being displayed
properly in your client...
"Fred's House" will come out in the spreadsheet as "Fred////s
House". (please remove the back slashes).

Cheers!

Alex

 
Reply With Quote
 
 
 
 
postings@alexshirley.com
Guest
Posts: n/a
 
      09-26-2005
This solved my problem:

http://groups.google.com/group/micro...ac895a5ab7ee9b

Cheers!

Alex

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with diacritic characters when exporting data to Excel ChrisN ASP .Net 0 09-19-2006 01:35 PM
Exporting to Excel with Chinese Characters tarunbajaj@gmail.com ASP .Net Datagrid Control 0 10-14-2005 11:29 PM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM
Handling special characters when exporting DataGrid to Excel Elisabeth Svensson via .NET 247 ASP .Net Datagrid Control 1 12-21-2004 11:46 AM
Characters bad when exporting asp.net datagrid to excel Goran Djuranovic ASP .Net 0 12-10-2004 06:44 PM



Advertisments