c#从sqlserver数据库导出的csv文件excel打开为乱码

tigerhunter83 2012-10-18 04:39:54
从网上查了,用vs 2010开发环境,sql server 2000,C#写的文件编码为utf-8,而excel 2007只支持ansi编码,用ultraedit打开文件并保存为ansi编码,excel打开就正常了,有什么办法可以编程解决这个问题?比如设置c#写的文件的编码方式,请高手指点。
...全文
372 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilinew 2012-10-27
  • 打赏
  • 举报
回复
同样问题
IEEE_China 2012-10-18
  • 打赏
  • 举报
回复

private static void DownLoadExcel(string path,Page page)
{
System.IO.FileInfo file = new System.IO.FileInfo(path);
page.Response.Clear();
page.Response.Charset = "GB2312";
page.Response.ContentEncoding = System.Text.Encoding.ASCII;
//page.Response.ContentEncoding = System.Text.Encoding.UTF8;
page.Response.AddHeader("Content-Disposition", "attachment; filename=" + page.Server.UrlEncode(file.Name));
page.Response.AddHeader("Content-Length", file.Length.ToString());
page.Response.ContentType = "application/ms-excel";
page.Response.WriteFile(file.FullName);
page.Response.Flush();
page.Response.End();
}
IEEE_China 2012-10-18
  • 打赏
  • 举报
回复
试试

private static void DownLoadExcel(string path,Page page)
{
System.IO.FileInfo file = new System.IO.FileInfo(path);
page.Response.Clear();
page.Response.Charset = "GB2312";
page.Response.ContentEncoding = System.Text.Encoding.ASCII;//修改编码ASCII
//page.Response.ContentEncoding = System.Text.Encoding.UTF8;
page.Response.AddHeader("Content-Disposition", "attachment; filename=" + page.Server.UrlEncode(file.Name));
page.Response.AddHeader("Content-Length", file.Length.ToString());
page.Response.ContentType = "application/ms-excel";
page.Response.WriteFile(file.FullName);
page.Response.Flush();
page.Response.End();
}

發糞塗牆 2012-10-18
  • 打赏
  • 举报
回复
C#应该可以设置编码格式的吧。不过你最好到.net专区问问好。我不记得C#怎么写了

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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