Excel下载乱码
1、前端:一定不可以以ajax的请求方式,不然会弹出乱码。
要使用<a href="../Ajax/AjaxPrint.ashx?action=PrintClick&Tid=" + Tid +"></a>的方式。
$("#PrintButton").append("<a id='hrefclick' href='../Ajax/AjaxPrint.ashx?action=PrintClick&Tid=" + Tid +"'></a>");
var el = document.getElementById('hrefclick');
el.click();
2、一般处理程序:
string fileName = Txt+".xls";//客户端保存的文件名
using (MemoryStream memoryStram = new MemoryStream())
{
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//把工作簿写入到内存流中
Workbook.Write(memoryStram);
context.Response.Clear();
//设置输出编码格式
//设置输出流
context.Response.ContentType = "application/octet-stream";
context.Response.Charset = "UTF-8";
//防止中文乱码
//设置输出文件名(顺序也是很重要的)
context.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + "\"");
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.Charset = "UTF-8";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
context.Response.BinaryWrite(memoryStram.ToArray());
Workbook = null;
memoryStram.Close();
memoryStram.Dispose();
}
最新文章
- ABP理论学习之验证DTO
- Android Fragment 使用技巧
- spring发布和接收定制的事件(spring事件传播)
- java导出excel(解决导出几万条数据内存溢出的问题)
- iOS8 VPN 应用内连接
- Testing - Selenium
- BZOJ4373 : 算术天才⑨与等差数列
- java笔记3之赋值运算符
- cf B. Fixed Points
- [Swust OJ 767]--将军回家(Dijkstra算法)
- SystemParametersInfo API学习(128个中文参数解释,215个实际值)
- TypeError: Cannot read property &;#39;style&;#39; of null 错误解决
- Catalan数总结
- Crystal Report 纵向排列,多列格式化
- DB2_自动生成值
- C#实现倒油算法
- include指令和include动作
- Java8-理解Colloctor
- BroadcastReceiver广播接受者
- 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试
热门文章
- 苹果iPhone 日历查询功能异常
- ChatGPT is at capacity right now.ChatGPT Plus subscriber login Add your email for a personalized login link的解决办法
- CSS:布局篇_用flex布局实现两边顶宽中间自适应(圣杯布局&;双飞翼布局)
- leetcode 跳跃游戏系列
- span&;不同字体
- redis底层数据结构之简单动态字符串(SDS)
- 083_SFDC Limit(二) 及良好的开发习惯
- SqlServer基礎
- Django里ORM常用关键字
- windows server 2012以上版本离线安装 net framework3.5 方法