在线等~~急急... Excel导出数据 数据少时 不会乱码 数据多时乱码...

TimLeaf 2008-12-11 10:46:17
这是开始的导出的代码...

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition","attachment; filename=\"" + HttpUtility.UrlEncode("AggregateTable.xls", System.Text.Encoding.UTF8) + "\";");
Response.Charset = "SHIFT-JIS";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("SHIFT-JIS");

下面就是:

Response.Write("<TABLE>");
...

在单独页面里面生成excel...然后发送到客户端...

为什么...
数据少时 不会乱码 数据多时乱码...
...全文
180 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanxiguang_0 2011-10-14
  • 打赏
  • 举报
回复
我是数据少的时候出现乱码,以前同事用这句话:Response.Charset = "gb2312";可以,但我不行,后来改成下面这句可以了:Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
yanlongwuhui 2008-12-11
  • 打赏
  • 举报
回复
关注
mengxj85 2008-12-11
  • 打赏
  • 举报
回复
学习
xiaoyuzi 2008-12-11
  • 打赏
  • 举报
回复
我是先生成一个excel文件,然后发送到客户端
// Create excel worksheet
ExcelServer.ExcelEnterpriseProject ecep = new ExcelServer.ExcelEnterpriseProject();
string filepath = Server.MapPath("~/ExcelTemplateStore/ExcelEnterpriseProject.xls");
ecep.TemplateFile = filepath;
ecep.CreateWorkbook();

// Add records
...
ecep.DataSource = lst;
...
ecep.AddRecords();

// Format cells
ecep.Format();

string sGenName = "CSDN社区.xls";
System.IO.FileStream fs = null;
fs = System.IO.File.Open(filepath, System.IO.FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();

// File name with chinese not more than 16?
Response.AddHeader("Content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(sGenName)));
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(btFile);
Response.End();
gengwanshanreally 2008-12-11
  • 打赏
  • 举报
回复
learn!
criedshy 2008-12-11
  • 打赏
  • 举报
回复
Response.Charset = "SHIFT-JIS";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("SHIFT-JIS");


都改成UTF-8

Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
RexZheng 2008-12-11
  • 打赏
  • 举报
回复
学习
wuyq11 2008-12-11
  • 打赏
  • 举报
回复

System.Globalization.CultureInfo ctinfo = new System.Globalization.CultureInfo( "zh-CN ", true);
Response.Charset = "gb2312 ";
看下
参考
http://www.cnblogs.com/HQT/archive/2005/08/05/208027.aspx

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧