asp.net导出execl和图片
2024-09-02 01:09:22
个人常用导出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();
最新文章
- js效果-多选只能选两项,如果超出自动取消第一次选的
- java数据结构_笔记(4)_图
- (转) Summary of NIPS 2016
- 连通性1 求无向图的low值
- 用JSON方式回调服务器
- 简单的json传送数据
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
- 【leetcode】Divide Two Integers (middle)☆
- jdbc 安装驱动
- 设计模式 - 模板方法模式(template method pattern) JFrame 具体解释
- AndroidStudio升级后出现Refresh gradle project和connection timed out的原因和解决方法
- EJB系列 - 会话Bean基础知识
- SharePoint 路在何方?
- 用python来更改小伙伴的windows开机密码,不给10块不给开机
- Windows 10忘记登录密码不用怕,系统U盘/光盘轻松重置
- SpringMVC(Springboot)返回文件方法
- python简单实现目录对比
- [转]油猴Tampermonkey-让百度云下载飞起来
- NetCore+Dapper WebApi架构搭建(一):基本框架
- 解决Pycharm中module &#39;pip&#39; has no attribute &#39;main&#39;的问题
热门文章
- Android中Handler原理
- JAVA设计模式之【建造者模式】
- 官方文档 Upgrading Elasticsearch
- VC 下加载 JPG / JPEG / GIF / PNG 图片最简单的方法
- PSSecurityException之PowerShell权限设置
- js效果之导航中英文转换
- Vue-cli 3.0 构建项目
- json对象获取长度以及字符串和json对象的转换
- 页面加载完成触发input[type=";file";]控件问题
- luoguP1555 尴尬的数字(暴力+map)