DataTable数据导出Excel 并且下载
public string Excel(System.Data.DataTable dt)
{
//模板的路径
string strUploadPath = HttpContext.Current.Server.MapPath("../template/");
//模板的名称
string strFileName = strUploadPath + "JobTicketTemplate.xlsx";
FileInfo TemplateFile = new FileInfo(strFileName);
//目标地址
string strPath = HttpContext.Current.Server.MapPath("../temp/");
//文件名称
string strNewFileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
FileInfo newFile = new FileInfo(strPath + strNewFileName);
int intCount = 2;
using (OfficeOpenXml.ExcelPackage package = new OfficeOpenXml.ExcelPackage(newFile, TemplateFile))
{
// Worksheets指的是第几个Excel
OfficeOpenXml.ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
worksheet.Cell(i + intCount, 1).Value = dt.Rows[i]["Name"].ToString();
worksheet.Cell(i + intCount, 2).Value = dt.Rows[i]["RealName"].ToString();
worksheet.Cell(i + intCount, 3).Value = dt.Rows[i]["Company"].ToString();
worksheet.Cell(i + intCount, 4).Value = dt.Rows[i]["IdentityCard"].ToString();
worksheet.Cell(i + intCount, 5).Value = dt.Rows[i]["Province"].ToString();
worksheet.Cell(i + intCount, 6).Value = dt.Rows[i]["Email"].ToString();
worksheet.Cell(i + intCount, 7).Value = dt.Rows[i]["Mobile"].ToString();
}
}
package.Save();
}
return strNewFileName;
}
最新文章
- Codeforces Round #348(VK Cup 2016 - Round 2)
- [Angularjs]视图和路由(四)
- java 的方法注释写在哪里?
- Linux运维工程师成长必经之路
- Date.prototype.format,js下的时间格式处理函数
- Looper、Hander、HandlerThread
- Swift - 动态添加删除TableView的单元格(以及内部元件)
- Zepto源码分析-event模块
- struts2(四)之输入校验
- 基于iTextSharp的PDF文档操作
- li标签中list-style-image如何居中
- ztree树应用
- 2. 常见的Queue
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: c
- sql server2005查询分析器显示行号方法
- html5调用手机陀螺仪实现方向辨识
- <;BEA-141281>; <;unable to get file lock, will retry ...>;
- 论文阅读:Videos as Space-Time Region Graphs
- jqGrid 清空单元格的方法
- jQuery插件初级练习4答案
热门文章
- CentOS_5.6下使用cmake编译MySQL_5.5.11教程
- 浅析被element.style所覆盖的样式
- 使用react native制作的微博客户端
- pthread的lowlevellock
- TreeSet对非自然顺序元素的排序
- spring cloud微服务搭建第一天
- 小谈ThinkPHP
- 解决css引用图片不显示问题:background-image: url(../image/document.png);
- java环境安装之不能安装exe文件
- Maven学习-优化和重构POM