导入:
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 }