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;

}

最新文章

  1. Codeforces Round #348(VK Cup 2016 - Round 2)
  2. [Angularjs]视图和路由(四)
  3. java 的方法注释写在哪里?
  4. Linux运维工程师成长必经之路
  5. Date.prototype.format,js下的时间格式处理函数
  6. Looper、Hander、HandlerThread
  7. Swift - 动态添加删除TableView的单元格(以及内部元件)
  8. Zepto源码分析-event模块
  9. struts2(四)之输入校验
  10. 基于iTextSharp的PDF文档操作
  11. li标签中list-style-image如何居中
  12. ztree树应用
  13. 2. 常见的Queue
  14. org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: c
  15. sql server2005查询分析器显示行号方法
  16. html5调用手机陀螺仪实现方向辨识
  17. &lt;BEA-141281&gt; &lt;unable to get file lock, will retry ...&gt;
  18. 论文阅读:Videos as Space-Time Region Graphs
  19. jqGrid 清空单元格的方法
  20. jQuery插件初级练习4答案

热门文章

  1. CentOS_5.6下使用cmake编译MySQL_5.5.11教程
  2. 浅析被element.style所覆盖的样式
  3. 使用react native制作的微博客户端
  4. pthread的lowlevellock
  5. TreeSet对非自然顺序元素的排序
  6. spring cloud微服务搭建第一天
  7. 小谈ThinkPHP
  8. 解决css引用图片不显示问题:background-image: url(../image/document.png);
  9. java环境安装之不能安装exe文件
  10. Maven学习-优化和重构POM