我的網站asp.net(C#)中導出.xls文件的功能有問題。
它將所有<tr>
保存爲一個字符串。 功能很好,但它不能保存適當的波蘭字符(Ł,ó,ê - 等)。
我該如何解決這個問題?從C#導出xls文件 - 不保存特殊字母
這裏是我的代碼:
string ExcelExport;
string StringExport;
(..)
protected void lvUsers_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item is ListViewDataItem)
{
(..)
StringExport = StringExport + string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", currentUser.name, currentUser.surname, tel, currentUser.email);
}
}
protected void btnDownloadList_Click(object sender, EventArgs e)
{
ExcelExport = "<table><tr><td>Name</td><td>Surname</td><td>Telephone</td><td>E-mail</td></tr><tr><td> </td><td> </td><td> </td><td> </td></tr>" + StringExport + "</table>";
Response.AddHeader("Content-disposition", "attachment; filename=raport.xls");
Response.Charset = "utf-8";
Response.ContentType = "application/ms-excel";
Response.Write(ExcelExport);
Response.End();
}
建議這似乎是一個編碼問題。你是用這種方式搜索的嗎? http://stackoverflow.com/questions/227575/encoding-problem-with-httpwebresponse可以幫助,或http://stackoverflow.com/questions/12190524/getting-response-as-a-string-c-net。 – Gnial0id