zoukankan      html  css  js  c++  java
  • EPPlus--ExcelPackage 导出Excel

    if (list != null && list.Count() > 0)
                {
                    ExcelPackage pck = new ExcelPackage();
    
                var ws = pck.Workbook.Worksheets.Add("QueryRecord");
    
                ws.Cells["A1"].Value = "证件类型";
                ws.Cells["B1"].Value = "合同编号";
                ws.Cells["C1"].Value = "证件号码";
                ws.Cells["D1"].Value = "企业名称/客户姓名";
                ws.Cells["E1"].Value = "查询人";
                ws.Cells["F1"].Value = "查询日期";
                ws.Cells["G1"].Value = "查询结果";
                ws.Cells["H1"].Value = "报告路径";
                ws.Cells["A1:H1"].Style.Font.Bold = true;
                ws.Cells[ws.Dimension.Address].AutoFitColumns();
    
                var row = 2;
                foreach (var item in list)
                {
                    var outlineLevel = 0;
                    //base info
                    ws.Cells[row, 1].Value = (item.IDENTIFY_TYPE.Equals(0) ? "个人" : (item.IDENTIFY_TYPE.Equals(100) ? "企业" : item.IDENTIFY_TYPE.ToString()));
                    ws.Cells[row, 2].Value = item.APPLICATION_NUMBER;
                    ws.Cells[row, 3].Value = item.IDENTIFY_NUMBER;
                    ws.Cells[row, 4].Value = item.APPLICANT_NAME;
                    ws.Cells[row, 5].Value = item.QUERY_EMPLOYEE;
                    ws.Cells[row, 6].Value = item.CREATED_DATETIME.ToString("yyyy-MM-dd HH:mm:ss.ffff");
                    ws.Cells[row, 7].Value = item.RespCode + "," + item.RespMsg;
                    ws.Cells[row, 8].Value = item.ECM_STORAGE_URL;
                    ws.Row(row).OutlineLevel = outlineLevel;
                    row++;
    
                }
                int rowCount = 1 + list.Count();
    
                ws.Cells["A1:H" + rowCount].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                ws.Cells["A1:H" + rowCount].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                ws.Cells["A1:H" + rowCount].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                ws.Cells["A1:H" + rowCount].Style.Border.Right.Style = ExcelBorderStyle.Thin;
    
                ws.OutLineSummaryBelow = false;
    
                    string fileName = "BPCQueryRecord_" + DateTime.Now.ToString("yyyyMMddHHmmss");
    
                    HttpContext.Current.Response.ContentType = "application/ms-excel";
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;  filename=" + fileName + ".xlsx");
    
                    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
                    HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray());
                    HttpContext.Current.Response.End();
                }
  • 相关阅读:
    Elasticsearch学习系列之介绍安装
    Python学习系列之文件操作
    Python学习系列之异常处理
    Python学习系列之装饰器
    windows 修改xhsell安全加密配置
    ipv6nginx错误
    zabbix 硬盘状态收集,制作表格
    申请免费ssl证书
    gitlab 搭建与迁移
    mogilefsdBUG mogilefsd[15624]: crash log: Modification of a read-only value attempted at /usr/local/share/perl5/Sys/Syscall.pm line 227
  • 原文地址:https://www.cnblogs.com/hofmann/p/13426777.html
Copyright © 2011-2022 走看看