Export datagrid to excel file

  • Thread starter Thread starter Amirallia
  • Start date Start date
A

Amirallia

Hello

Here is my code to export a datagrid to Excel, it's work but the no
ASCII caracter are not correctly exported (for example : caracter "é"
)

Response.Clear()
Response.Buffer = True

Response.AddHeader("content-disposition",
"attachment;filename=Final.xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = "UTF-8"

Dim monStringWriter As System.IO.StringWriter = New
System.IO.StringWriter
Dim monHtmlTextWriter As HtmlTextWriter = New
HtmlTextWriter(monStringWriter)
Me.dg1.RenderControl(monHtmlTextWriter)
Response.Write(monStringWriter.ToString())
Response.End()

Any idea to export correctly ?
 
I believe you need to set your charcater encoding type along with yuor
application. Its something like this but you'll need to dig about to get it
right.

Response.ContentType = "application/vnd.ms-excel;charset=windows-1251"

Regards

John Timney (MVP)
 
John Timney (MVP) avait prétendu :
I believe you need to set your charcater encoding type along with yuor
application. Its something like this but you'll need to dig about to get it
right.

Response.ContentType = "application/vnd.ms-excel;charset=windows-1251"

Regards

John Timney (MVP)

Thanks, but it doesn't work !

But what do you mean when you write: charcater encoding type along with
your application
 
charset=windows-1251 is character charcater encoding type

application/vnd.ms-excel;charset=windows-1251 is charcater encoding type
along with your application
 
Back
Top