码迷,mamicode.com
首页 > 其他好文 > 详细

使用ExcelPackage进行Excel报表

时间:2018-04-08 14:38:24      阅读:863      评论:0      收藏:0      [点我收藏+]

标签:name   val   excel   cto   pen   price   获取   dir   reac   

Nuget包名为

epplus.core

 

命名空间OfficeOpenXml

 

  string localFileName = path + Path.DirectorySeparatorChar + fileName;
                FileInfo file = new FileInfo(localFileName);
                using (ExcelPackage package = new ExcelPackage(file))
                {
                    ExcelWorkbook wb = package.Workbook;

                    //配置文件属性  
                    wb.Properties.Title = "库存导入模板";
                    // 添加worksheet
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("商品库存");
                    //添加头
                    worksheet.Cells[1, 1].Value = "商品ID";
                    worksheet.Cells[1, 2].Value = "商品名称";
                    worksheet.Cells[1, 3].Value = "货号";
                    worksheet.Cells[1, 4].Value = "原价";
                    worksheet.Cells[1, 5].Value = "售价";
                    worksheet.Cells[1, 6].Value = "数量";
                    worksheet.Cells[1, 7].Value = "库存规格1";
                    worksheet.Cells[1, 8].Value = "库存规格2";

                    //获取当前商户库存数据模板
                    var items = _pser.GetImportInnentoryList(CurrentVendorID);
                    int rowindex = 1;
                    foreach (var item in items)
                    {
                        rowindex++;
                        //添加值
                        worksheet.Cells[rowindex, 1].Value = item.ProductID;
                        worksheet.Cells[rowindex, 2].Value = item.ProductName;
                        worksheet.Cells[rowindex, 3].Value = item.ArtNo;
                        worksheet.Cells[rowindex, 4].Value = item.TagPrice;
                        worksheet.Cells[rowindex, 5].Value = item.Price;
                        worksheet.Cells[rowindex, 6].Value = item.Quantity;
                        worksheet.Cells[rowindex, 7].Value = item.Specification1;
                        worksheet.Cells[rowindex, 8].Value = item.Specification2;

                    }
                    package.Save();
                }

跑是肯定跑不通的,因为我是COPY的

使用ExcelPackage进行Excel报表

标签:name   val   excel   cto   pen   price   获取   dir   reac   

原文地址:https://www.cnblogs.com/AnAng/p/8744335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!