ASP.NET 导出Excel乱码的终极解决
我用了这个 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
还是出现乱码
在asp.net中导出excel 中比较通行的做法是 Response.ContentType = "application/vnd.ms-excel";
然后直接向里面扔 html 的table
就是在 输出html两头输出
Response.Write("<html><head><meta http-equiv=Content-Type content=/"text/html; charset=GB2312/">");
Response.Write("</body></html>");
这样就解决了,究其原因,大概是 excel读到 utf-8自己会改变字符集读取方式吧,其实文件本身改变为unicode字符集就可以读取了,但不知道response怎么输出unicode
遇到 0开头的字符串输出时,td 为
string.Format("<td style='mso-number-format:General;mso-number-format:/"{1}/"'>{0}</td>", dt.Rows[j][i], @"/@");