I'm doing some Excel Exports on the ASP.NET Site.
Everything works except of the Encoding. When I open it in Excel, it looks like this:
Eingabe Kosten je Ger?¤t Ger?¤t:
Ger?¤tebezeichnung:
Betriebsmittel Heiz??l in a??: 4
Dieselverbrauch in a??: 4
This is my code:
Response.Clear();
Response.ContentType = "application/ms-excel";
Response.AddHeader("Content-Disposition", "inline;filename=NachkalkGeraete.xls;");
var writer = new HtmlTextWriter(Response.Output);
SomeControl.RenderControl(writer); /* FormView, Table, DataGrid... */
Response.End();
I've already tried explicitly set the Encoding.. but no change occured:
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=NachkalkGeraete.xls");
Response.BufferOutput = true;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "UTF-8";
EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
SomeControl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
What is wrong, please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…