导出EXCEL【Web方式HTML通过拼接html中table】
DataTable dt= GetTaskList(int.MaxValue);
StringBuilder table = new StringBuilder();
table.Append("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>");
//在拼接table时,需要加入这句,否则会出现乱码
table.Append("<table cellpadding='1' cellspacing='1' style='width:1200px; background:#CCCCCC;font-size:13px;'>");
table.Append("<tr>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>酒店ID</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>酒店名称</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>检查人</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>开始日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>结束日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>自查日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>整改日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>复核日期</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>类型</td>");
table.Append("<td style='background:#666666; height:25px; color:#FFF; font-weight:bold; text-align:center;'>状态</td>");
table.Append("</tr>");
foreach (DataRow dr in dt.Rows)
{
table.Append("<tr>");
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["HotelID"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["HotelName"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["CheckUser"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["BeginDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["EndDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["CheckSumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["RectifySumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", HotelInspection.Component.CommonUtility.StrToDateTime(dr["ReviewSumbitDate"]).ToString("yyyy-MM-dd"));
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["TaskFrom"]);
table.AppendFormat("<td style='background:#FFFFFF; height:25px;'>{0}</td>", dr["TaskStatus"]);
table.Append("</tr>");
}
table.Append("</table>");
string filename = DateTime.Now.ToString("yyyyMMddHHmmss")+".xls";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + "\"");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel;";
HttpContext.Current.Response.Write(table.ToString());
HttpContext.Current.Response.End();
导出EXCEL【Web方式HTML通过拼接html中table】的更多相关文章
- poi 导出excel 异常处理方式--曲线救国法
excel 导出不算什么新鲜的话题.目前各种生成excel的开源jar包,poi,jxtl等.但是下载过程中如果出现异常该如何处理呢. 翻了之前的几个项目中的excel导出,有的异常就直接抛了出去,有 ...
- MVC 实现表格数据导出Excel(NPOI方式)
前端View(@ViewBag为查询条件): <span id="exprobtn" class="btn_blue" style="dispa ...
- 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型
如何获取一个表中的字段总数 1.function show columns from 表明: 结果 : 2.functiuon select count(*) from INFORMATION_SCH ...
- C# NPOI 导入与导出Excel文档 兼容xlsx, xls(xf13中已经引用了xlsx的npoi)
这里使用的NPOI版本为: 2.1.3.1 官方下载地址: http://npoi.codeplex.com/releases 版本内包含.Net 2.0 与.Net 4.0 .Net 4.0中包含文 ...
- NPOI 导出Excel 数据方式
使用NPOI的库进行Excel导出操作 公共帮助类: using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System; using S ...
- POI导出excel的简单demo
目前使用过两种导出excel的方式,一种是如题所示的使用POI的方式进行数据的导出,这种方式一般只有在处理比较多的数据或者说需要导出的excel表格中有图片之类的需要特殊处理的文件的时候使用:还有一种 ...
- 公司项目笔记-导出excel
一.asp.net中导出Excel的方法: 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出流写给浏览 ...
- html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式
先上代码 <script type="text/javascript" language="javascript"> var idTmr; ...
- java中使用jxl导出Excel表格详细通用步骤
该方法一般接收两个参数,response和要导出的表格内容的list. 一般我们将数据库的数据查询出来在页面进行展示,根据用户需求,可能需要对页面数据进行导出. 此时只要将展示之前查询所得的数据放入s ...
随机推荐
- Oracle 11g 中恢复管理器RMAN介绍
这是我平时摘录的笔记,从管理艺术那本书上摘录出来的,放到这里 RMAN 可在数据库服务器的帮助下从数据库内备份数据文件,可构造数据文件映像副本.控制文件和控制文件映像.对当日志 SPFILE 和RMA ...
- sphinx增量索引
首先建立一个计数表,保存数据表的最新记录ID CREATE TABLE `sph_counter` ( `id` int(11) unsigned NOT NULL, `max_id` int(1 ...
- 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory
运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
- Linux traceroute
一.简介 traceroute 通过发送 TCP 数据包向目标端口进行探测,以检测源到目标服务器的整个链路上相应端口的连通性情况. 二.语法 -n 直接使用IP地址而非主机名称(禁用 DNS 反查 ...
- JasperReports教程:Report Data Sources
原文地址:http://www.tutorialspoint.com/jasper_reports/jasper_report_data_sources.htm Datasources是一个结构化的数 ...
- 在Asp.Net Core中添加区域的简单实现
使用区域,可以有效的对业务进行隔离,各种业务及分工可以更灵活.在Asp.Net Core中启用区域也是极简单的. 使用步骤: 1.在 Startup.cs 中添加区域的路由: app.UseMvc(r ...
- nopcommerce商城系统--如何编写一个插件
原址:http://www.nopcommerce.com/docs/77/how-to-write-a-nopcommerce-plugin.aspx plug-in (或 plugin)是一个为更 ...
- [转]VS2015 cordova尝试-camera
本文转自:http://blog.csdn.net/greystar/article/details/47973837 1. 确保环境正常,如出现错误 ,安下载android sdk 相关版本,我在这 ...
- Yii提供的Htmler助手checkboxList可自定义Checkbox输出格式
foreach($catetags as $cate){ echo Html::checkboxList('category_id','',$cate,['item'=>'customCheck ...