EPPlus导入导出不占用进程

导入:

1 using (ExcelPackage package = new ExcelPackage(new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
2 {
3     ExcelWorksheet sheet = package.Workbook.Worksheets[1];
4     object title = sheet.Cells[3, 1].Value ?? "";
5     // do
6     int row = 4;
7 }

导出

 1 using (var package = new ExcelPackage(new FileInfo(sfd.FileName)))
 2 {
 3     var sheet = package.Workbook.Worksheets.Add("Abc");
 4     int rowIndex = 1;
 5     sheet.Cells[rowIndex, 1].Value = "日期";
 6     sheet.Cells.AutoFitColumns();
 7     sheet.Cells[1, 1, rowIndex, 12].Style.Border.Left.Style = ExcelBorderStyle.Thin;
 8     sheet.Cells[1, 1, rowIndex, 12].Style.Border.Top.Style = ExcelBorderStyle.Thin;
 9     sheet.Cells[1, 1, rowIndex, 12].Style.Border.Right.Style = ExcelBorderStyle.Thin;
10     sheet.Cells[1, 1, rowIndex, 12].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
11     package.Save();
12     package.Dispose();
13 }

 

posted on 2018-04-11 17:04  jonney_wang  阅读(257)  评论(0编辑  收藏  举报

导航