E
Elisabeth Svensson via .NET 247
I am trying to export a DataGrid to Excel using a HtmlTextWriter and the DataGrid.RenderControl method. Everything is working fine except that certain swedish characters in the DataGrid (?, ?, ?) gets displayed as ?? ?? ?? in the Excel file.
Can anyone tell me how to solve this?
This is the code I am using:
//create a string writer
System.IO.StringWriter stringWrite = new StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//first let's clean up the response.object
Response.Clear();
Response.Charset = "";
//set the response mime type for excel
Response.ContentType = "application/vnd.ms-excel";
//Tell the datagrid to render itself to our htmltextwriter
dgIssues.RenderControl(htmlWrite);
//all that's left is to output the html
Response.Write(stringWrite.ToString());
Response.End();
Can anyone tell me how to solve this?
This is the code I am using:
//create a string writer
System.IO.StringWriter stringWrite = new StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//first let's clean up the response.object
Response.Clear();
Response.Charset = "";
//set the response mime type for excel
Response.ContentType = "application/vnd.ms-excel";
//Tell the datagrid to render itself to our htmltextwriter
dgIssues.RenderControl(htmlWrite);
//all that's left is to output the html
Response.Write(stringWrite.ToString());
Response.End();