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 的
来源: http://www.bubuko.com/infodetail-2554360.html