1. 程式人生 > >使用ExcelPackage進行Excel報表

使用ExcelPackage進行Excel報表

tle val end RR plus owin lis foreach elpa

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報表