从C#WebPart导出到Excel中的编码问题

我有简单的C#WebPart(为WSS 3.0编写)。 其中一个function是将数据导出为ex​​cel。 一切正常,但我有显示波兰语字母的问题。 我试图改变几乎所有的东西,阅读了很多论坛和博客,仍然不知道我做错了什么。 听到是我的代码:

HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName)); HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(1250); // this is correct encoding code using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Table table = new Table(); TableRow row = new TableRow(); // (...) fills header row table.Rows.Add(row); foreach (User user in userLists) { TableRow row1 = new TableRow(); // (...) fills row with data table.Rows.Add(row1); } table.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End(); } } 

我使用类似的方法将数据导出到CSV文件,并且显示波兰标志没有问题。 有谁知道我在做什么错?

有时当我在导入数据时遇到这样的问题时,有助于重置被搞砸的部分的数据格式。 您可能想尝试重置文档的语言,以确保问题不是您的代码,但Excel由于一些不明确的原因而默认为英文。 祝你好运。