Export to Excell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top