zoukankan      html  css  js  c++  java
  • .NET/C#- EPPLUS DEMO

      强大的导出EXCEL,比NPOI更好用,更强大,可惜只有4.0版本的。

      记录一下DEMO

                    var sheet = p.Workbook.Worksheets.Add("My Sheet");
    
                    //Cells的起始索引是1
                    sheet.Cells[1, 1].Value = 1234.123;
                    sheet.Cells[2, 1].Value = 1;
                    sheet.Cells[3, 1].Value = 2;
                    sheet.Cells[4, 1].Value = 3;
    
                    sheet.Cells[1, 1].Style.Numberformat.Format = "#,##0.00";//这是保留两位小数
    
    
                    var sheet2 = p.Workbook.Worksheets.Add("My Sheet2");
                    sheet2.Cells[1, 1].Value = "jie";
                    sheet2.Cells[2, 1].Value = "xiaom";
                    sheet2.Cells[3, 1].Value = "ccx";
                    sheet2.Cells[4, 1].Value = "zhangs";
    
                    sheet2.Cells[1, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//水平居中
                    sheet2.Cells[1, 1].Style.Font.Bold = true;//字体为粗体
                    sheet2.Cells[1, 1].Style.Font.Size = 22;//字体大小
    
    
                    p.SaveAs(new FileInfo(@"F:Tempoutput.xlsx"));

    -------------------------------------------------

            public ActionResult ExportExcel()
            {
                // 写入到客户端 
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
    
                using (var p = new ExcelPackage(ms))
                {
                    var sheet = p.Workbook.Worksheets.Add("My Sheet");
    
                    //Cells的起始索引是1
                    sheet.Cells[1, 1].Value = 1234.123;
                    sheet.Cells[2, 1].Value = 1;
                    sheet.Cells[3, 1].Value = 2;
                    sheet.Cells[4, 1].Value = 3;
    
                    sheet.Cells[1, 1].Style.Numberformat.Format = "#,##0.00";//这是保留两位小数
    
    
                    var sheet2 = p.Workbook.Worksheets.Add("My Sheet2");
                    sheet2.Cells[1, 1].Value = "jie";
                    sheet2.Cells[2, 1].Value = "xiaom";
                    sheet2.Cells[3, 1].Value = "ccx";
                    sheet2.Cells[4, 1].Value = "zhangs";
    
                    sheet2.Cells[1, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//水平居中
                    sheet2.Cells[1, 1].Style.Font.Bold = true;//字体为粗体
                    sheet2.Cells[1, 1].Style.Font.Size = 22;//字体大小
    
    
                    //写到客户端(下载)
                    HttpContext.Response.Clear();
                    HttpContext.Response.AddHeader("content-disposition", "attachment;  filename=FileFlow.xlsx");
                    HttpContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    HttpContext.Response.BinaryWrite(p.GetAsByteArray());
                    //ep.SaveAs(Response.OutputStream);    第二种方式
                    HttpContext.Response.Flush();
                    HttpContext.Response.End();  
    
    
                }
    
                return null;
            }
  • 相关阅读:
    linux系统中将一列数据转换为若干列数据(列的顺序不变)
    linux系统中将矩形数据转换为一行、一列的形式
    linux系统中实现文本转置。
    linux shell 如何将多列数据变为一行数据
    linux系统中如何将一行数据变为一列
    bash: unlzma: command not found...
    linux系统中实现对行的批量替换
    linux系统中对指定行的字符串进行替换
    linux系统中对指定列的数据中的字符串进行替换
    linux系统中如何将每行特定数目字符后的字符替换为指定字符
  • 原文地址:https://www.cnblogs.com/cxeye/p/5072026.html
Copyright © 2011-2022 走看看