W
Webmills
Hi
I am exporting a datagrid to Excel using the code as below. The problem
that I am experiencing is that if my datagrid includes
characters, spurious A with an accent characters appear within the
export. I am certain that this should be remedied by changin the
charset and/or encoding, but I cannot seem to get it right.
// Set up the page for export.
this.EnableViewState = false;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = Encoding.GetEncoding("utf-8");
// Set the content type.
Response.ContentType = "application/vnd.ms-excel";
// Set the title.
Response.AddHeader("content-disposition", "attachment; filename=" +
TITLE + ".xls");
// Create the string builder.
StringBuilder stringBuilder = new StringBuilder();
// Append the page start.
stringBuilder.AppendFormat("<html><head><link href=\"{0}/Styles.css\"
rel=\"stylesheet\" type=\"text/css\" /></head><body>",
Session["RootPath"]);
// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new
StringWriter(stringBuilder, CultureInfo.InvariantCulture));
// Render the controls.
phrTitle.RenderControl(htmlTextWriter);
phrFinished.RenderControl(htmlTextWriter);
dgdData.RenderControl(htmlTextWriter);
// Append the page end.
stringBuilder.Append("</body></html>");
// Write the output.
Response.Write(stringBuilder.ToString());
Response.End();
Any ideas?
Regards
James
I am exporting a datagrid to Excel using the code as below. The problem
that I am experiencing is that if my datagrid includes
characters, spurious A with an accent characters appear within the
export. I am certain that this should be remedied by changin the
charset and/or encoding, but I cannot seem to get it right.
// Set up the page for export.
this.EnableViewState = false;
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.ContentEncoding = Encoding.GetEncoding("utf-8");
// Set the content type.
Response.ContentType = "application/vnd.ms-excel";
// Set the title.
Response.AddHeader("content-disposition", "attachment; filename=" +
TITLE + ".xls");
// Create the string builder.
StringBuilder stringBuilder = new StringBuilder();
// Append the page start.
stringBuilder.AppendFormat("<html><head><link href=\"{0}/Styles.css\"
rel=\"stylesheet\" type=\"text/css\" /></head><body>",
Session["RootPath"]);
// Create the html text writer.
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new
StringWriter(stringBuilder, CultureInfo.InvariantCulture));
// Render the controls.
phrTitle.RenderControl(htmlTextWriter);
phrFinished.RenderControl(htmlTextWriter);
dgdData.RenderControl(htmlTextWriter);
// Append the page end.
stringBuilder.Append("</body></html>");
// Write the output.
Response.Write(stringBuilder.ToString());
Response.End();
Any ideas?
Regards
James