个人常用导出execl方法:

#region "导出文档"
/// <summary>
/// Export("application/ms-excel", DateTime.Now.ToString("yyyyMMhhddmmss") + ".xls", htmlExcel, "统计");
/// </summary>
/// <param name="Filetype">导出类型</param>
/// <param name="FileName">导出名称</param>
/// <param name="html">用html拼装出来的要导出的内容</param>
/// <param name="sheetName"></param>
private void Export(string Filetype, string FileName, string html, string sheetName)
{
StringWriter sw = new StringWriter();
sw.WriteLine("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
sw.WriteLine("<head>");
sw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
sw.WriteLine("<!--[if gte mso 9]>");
sw.WriteLine("<xml>");
sw.WriteLine(" <x:ExcelWorkbook>");
sw.WriteLine(" <x:ExcelWorksheets>");
sw.WriteLine(" <x:ExcelWorksheet>");
sw.WriteLine(string.Format(" <x:Name>{0}</x:Name>", sheetName));
sw.WriteLine(" <x:WorksheetOptions>");
sw.WriteLine(" <x:Print>");
sw.WriteLine(" <x:ValidPrinterInfo />");
sw.WriteLine(" </x:Print>");
sw.WriteLine(" </x:WorksheetOptions>");
sw.WriteLine(" </x:ExcelWorksheet>");
sw.WriteLine(" </x:ExcelWorksheets>");
sw.WriteLine("</x:ExcelWorkbook>");
sw.WriteLine("</xml>");
sw.WriteLine("<![endif]-->");
sw.WriteLine(" <style type='text/css'>.td_text { background-color: #ECF9FC; text-align: left; text-align: left; } .td_value { background-color: #FFFFFF; text-align: left; border-top: medium none; } .tableGg { background-color: #82D1E7; border-top-width: 0px; border-bottom-width: 0px; width: 700px; } </style>");
sw.WriteLine("</head>");
sw.WriteLine("<body>");
sw.WriteLine(html);
sw.WriteLine("</body>");
sw.WriteLine("</html>");
sw.Close(); Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlDecode(FileName, Encoding.UTF8).ToString());
Response.ContentType = Filetype;
this.EnableViewState = false;
Response.Write(sw);
Response.End();
}
#endregion

个人常用导出图片方法,性能不是很好:

   //Model.Data 这是图片的二进制流,Data是对象Model的一个属性byte[]
Response.ContentType = "image/jpeg";
if (Model.Data != null)
{
Response.BinaryWrite(Model.Data);
}
Response.End();

最新文章

  1. js效果-多选只能选两项,如果超出自动取消第一次选的
  2. java数据结构_笔记(4)_图
  3. (转) Summary of NIPS 2016
  4. 连通性1 求无向图的low值
  5. 用JSON方式回调服务器
  6. 简单的json传送数据
  7. 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
  8. 【leetcode】Divide Two Integers (middle)☆
  9. jdbc 安装驱动
  10. 设计模式 - 模板方法模式(template method pattern) JFrame 具体解释
  11. AndroidStudio升级后出现Refresh gradle project和connection timed out的原因和解决方法
  12. EJB系列 - 会话Bean基础知识
  13. SharePoint 路在何方?
  14. 用python来更改小伙伴的windows开机密码,不给10块不给开机
  15. Windows 10忘记登录密码不用怕,系统U盘/光盘轻松重置
  16. SpringMVC(Springboot)返回文件方法
  17. python简单实现目录对比
  18. [转]油猴Tampermonkey-让百度云下载飞起来
  19. NetCore+Dapper WebApi架构搭建(一):基本框架
  20. 解决Pycharm中module &#39;pip&#39; has no attribute &#39;main&#39;的问题

热门文章

  1. Android中Handler原理
  2. JAVA设计模式之【建造者模式】
  3. 官方文档 Upgrading Elasticsearch
  4. VC 下加载 JPG / JPEG / GIF / PNG 图片最简单的方法
  5. PSSecurityException之PowerShell权限设置
  6. js效果之导航中英文转换
  7. Vue-cli 3.0 构建项目
  8. json对象获取长度以及字符串和json对象的转换
  9. 页面加载完成触发input[type=&quot;file&quot;]控件问题
  10. luoguP1555 尴尬的数字(暴力+map)