以前代码:
public static void htmlToExcel(HttpContext context, string title, string html, string fileCss = "", string SheetName = "")
{
var Response = context.Response;
string html1 = html;
Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment; filename=" + title + ".xls");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); if (fileCss != "")
{
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
cssText += line;
}
sr.Close();
Response.Write("<style>" + cssText + "</style>");
} Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
if (!Exec.IsNullOrEmpty(SheetName))
{
Response.Write("<x:Name>" + SheetName + "</x:Name>");
}
else
{
Response.Write("<x:Name>Report Data</x:Name>");
} Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write(html1);//HTML
Response.Flush();
Response.End();
}

  

   public static void htmlToExcel(HttpContext context, string title, string html, string fileCss = "", string SheetName = "")
{
var Response = context.Response;
string html1 = html;
Response.ContentType = "application/force-download"; title = HttpUtility.UrlEncode(title, System.Text.Encoding.GetEncoding("UTF-8")); Response.AddHeader("content-disposition", "attachment; filename=" + title + ".xls");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); if (fileCss != "")
{
string cssText = string.Empty;
StreamReader sr = new StreamReader(fileCss);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
cssText += line;
}
sr.Close();
Response.Write("<style>" + cssText + "</style>");
} Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
if (!Exec.IsNullOrEmpty(SheetName))
{
Response.Write("<x:Name>" + SheetName + "</x:Name>");
}
else
{
Response.Write("<x:Name>Report Data</x:Name>");
} Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write(html1);//HTML
Response.Flush();
Response.End();
}

  给文件名通过转码的方式进行导出。

参考:http://blog.csdn.net/tongxinxiao/article/details/43733881

解决导出为Excel时文件名乱码的问题。的更多相关文章

  1. C#中解决Response.AddHeader("Content-Disposition", "attachment; filename=" + filename)下载文件时文件名乱码的问题

    问题:下载文件时文件名乱码怎么解决? 在C#写后台代码过程中,经常遇到下载文件出现文件名乱码的问题,在网上找了很多方法,总是存在浏览器不兼容的问题,当IE浏览器不乱码时,火狐浏览器就会乱码,后来经过反 ...

  2. ie浏览器下载文件时文件名乱码

    做一个文件下载功能时,用ie浏览器下载时文件名乱码,火狐和谷歌正常,修改后ie显示正常,修改方法如下: @RequestMapping(value = "fileDownload" ...

  3. Excel导出不同浏览器下文件名乱码问题

    解决思路:通过请求头中的User-Agent参数中的信息来区分不同浏览器 public Object exportPz(HttpServletRequest request, HttpServletR ...

  4. Ecshop 后台导出订单Excel时, 内存溢出的解决方法

    今天继续跟大家分享一下,在我配置Ecshop时的问题. 今天的问题是在后台想要导出订单列表Excel时出现的内存溢出.错误提示如下 问题:  Fatal error: Allowed memory s ...

  5. 完美解决ExtJs6上传中文文件名乱码,后端SpringMVC

    ExtJs上传中文文件名乱码,观察请求. ExtJs6上传乱码从后台无法解决,因为文件名请求里面就已经乱码了,后台无法解码. 除非请求参数正确没有乱码,后台因为编码设置不一样,可以通过后台处理乱码 这 ...

  6. 解决Java POI 导出Excel时文件名中文乱码,兼容浏览器

    String agent = request.getHeader("USER-AGENT").toLowerCase(); response.setContentType(&quo ...

  7. 如何解决android studio 运行时中文乱码的问题

    相信很多朋友都会遇到android studio 在MAC OS中运行的时候中文乱码.而在代码编辑的时候正常.经过几天的不断寻找解决办法,终于解决了 比如: Toast.makeText(MainAc ...

  8. 解决 jsp:include 引用文件时出现乱码的问题

    阐述问题前,先来看一下下面这张图片左侧iframe中的乱码页面: 这个就是让我纠结好一阵子的乱码截图: 这个乱码页面中是使用了<jsp:include>引用标签后出现了这个问题: 源码截图 ...

  9. 解决python解析文件时输出乱码

    首先获取到json模块,encoding指定文件编码utf-8,errors报错时忽略错误,print()输出结果看看是否有问题. # -*- coding: utf-8 -*- import jso ...

随机推荐

  1. 基于OMAPL138的Linux字符驱动_GPIO驱动AD9833(二)之cdev与read、write

    基于OMAPL138的Linux字符驱动_GPIO驱动AD9833(二)之cdev与read.write 0. 导语 在上一篇博客里面,基于OMAPL138的字符驱动_GPIO驱动AD9833(一)之 ...

  2. System.Speech使用

    使用微软语音库 使用微软语音库可以很快速的制作一个小应用,比如一个唐诗的朗诵工具.本示例也是使用微软语音库,制作了一个唐诗宋词朗诵的应用,仅供加深学习印象 首先是要引入System.Speech库 然 ...

  3. 39-Role以及Claims授权

    asp.net core多鼓励使用claims授权 1-使用role授权 在类或方法上贴上Roles,这样就知道有user的角色才可以访问 [Authorize(Roles="user&qu ...

  4. Spring MVC: 环境搭建并实现简易的HelloWorld

    第一步:使用配置Tomcat服务器的Eclipse新建一个名为“TestSpringMVC”的web项目 第二步:将所使用的jar包复制到WEB-INF/lib目录下 第三步:在web.xml中配置D ...

  5. 「日常训练」Common Subexpression Elimination(UVa-12219)

    今天做的题目就是抱佛脚2333 懂的都懂. 这条题目干了好几天,最后还是参考别人的代码敲出来了,但是自己独立思考了两天多,还是有收获的. 思路分析 做这条题我是先按照之前的那条题目(The SetSt ...

  6. Tuxedo 通讯方式解析

    本节根据tuxedo自带samples的例子,让其运行起来.并通过这个例子,深入的理解tuxedo的通讯方式. 进入tuxedo的安装目录,samples目录下自带了一些例子 [root@localh ...

  7. (转) Unreal Engine 4 Custom Shaders Tutorial

    说明: 1.这里的Custom Shaders 为且仅为 Custom Node的使用和USF的包含.并非全局Shader和Material Shader. 2.原文来源:https://www.ra ...

  8. C# 结构类型与类的区别

    结构类型是值类型:类是引用类型: 内存位置不同,结构类型在应用程序的堆栈中:类对象在托管中: 是否改变源对象

  9. cordova相关

    官网 安装nodejs 常用命令: $ npm install -g cordova //安装cordova $ cordova create [project name] //创建工程 $ cord ...

  10. mysql分布式技术

    所有的分布式技术 dobble zokkiper ngix