首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

把GridView中的内容导入Excle中文显示乱码,用 BinaryWriter 的方法写入解决思路

2012-01-11 
把GridView中的内容导入Excle中文显示乱码,用 BinaryWriter 的方法写入代码如下StringWriterswnewStringW

把GridView中的内容导入Excle中文显示乱码,用 BinaryWriter 的方法写入
代码如下

StringWriter   sw   =   new   StringWriter();
                HtmlTextWriter   htw   =   new   HtmlTextWriter(sw);
                this.GridView1.RenderControl(htw);
                string   strHtml   =   sw.ToString().Trim();

                string   ExcelFileName   =   Session[ "user_code "]+ "temp.xls ";
                string   FilePhysicialPathName   =   Request.PhysicalApplicationPath;

                //生成的Excel文件名
                string   objectExcelFileName   =   Path.Combine(FilePhysicialPathName,   ExcelFileName);

                if   (File.Exists(objectExcelFileName))
                {
                        File.Delete(objectExcelFileName);
                }
                FileStream   fs   =   new   FileStream(objectExcelFileName,   FileMode.Create);
                BinaryWriter   bw   =   new   BinaryWriter(fs,   Encoding.GetEncoding( "GBK "));
                bw.Write(strHtml);
                Response.Redirect( "../ "+Session[ "user_code "]+ "temp.xls ");
                bw.Close();
                fs.Close();
把Encoding.GetEncoding( "GBK ")设置成utf-8或者GB2312都不行,请用过此方法生成Excel的朋友赐教。

[解决办法]
参考一下这:
http://dotnet.aspx.cc/article/700bd3fa-a17f-41dc-b258-0dc572625700/read.aspx
[解决办法]
StreamWriter fs = new StreamWriter (objectExcelFileName, false,Encoding.GetEncoding( "GB2312 ")););
fs.Write(strHtml);
fs.Close();
[解决办法]
StreamWriter fs = new StreamWriter (objectExcelFileName, false,Encoding.UTF7);
fs.Write(strHtml);
fs.Close();
为何是UTF7呢?

我也想知道,为什么UTF8就不行,要UTF7就正常了,以前做项目遇到这个问题,现在也还没明白
[解决办法]
http://www.aspnet168.com.cn/
或许能找到你感兴趣的问题

热点排行