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();

}

最新文章

  1. ABP理论学习之验证DTO
  2. Android Fragment 使用技巧
  3. spring发布和接收定制的事件(spring事件传播)
  4. java导出excel(解决导出几万条数据内存溢出的问题)
  5. iOS8 VPN 应用内连接
  6. Testing - Selenium
  7. BZOJ4373 : 算术天才⑨与等差数列
  8. java笔记3之赋值运算符
  9. cf B. Fixed Points
  10. [Swust OJ 767]--将军回家(Dijkstra算法)
  11. SystemParametersInfo API学习(128个中文参数解释,215个实际值)
  12. TypeError: Cannot read property &amp;#39;style&amp;#39; of null 错误解决
  13. Catalan数总结
  14. Crystal Report 纵向排列,多列格式化
  15. DB2_自动生成值
  16. C#实现倒油算法
  17. include指令和include动作
  18. Java8-理解Colloctor
  19. BroadcastReceiver广播接受者
  20. 《软件测试自动化之道》读书笔记 之 SQL 存储过程测试

热门文章

  1. 苹果iPhone 日历查询功能异常
  2. ChatGPT is at capacity right now.ChatGPT Plus subscriber login Add your email for a personalized login link的解决办法
  3. CSS:布局篇_用flex布局实现两边顶宽中间自适应(圣杯布局&amp;双飞翼布局)
  4. leetcode 跳跃游戏系列
  5. span&amp;不同字体
  6. redis底层数据结构之简单动态字符串(SDS)
  7. 083_SFDC Limit(二) 及良好的开发习惯
  8. SqlServer基礎
  9. Django里ORM常用关键字
  10. windows server 2012以上版本离线安装 net framework3.5 方法