public List <Person> TranslateExcel(string targetWS) { ExcelWorksheet ws = worksheets.FirstOrDefault(p => p.Name == targetWS); List <Person> result = ParseData(ws); return(result); }
public List <ExcelRow> Excute(bool isFirstRowAsIndex = false) { using (excelStream) using (ExcelPackage package = new ExcelPackage(excelStream)) { ExcelWorksheets workSheets = package.Workbook.Worksheets; ExcelWorksheet workSheet = workSheets.FirstOrDefault(); var array = workSheet?.Cells?.Value as object[, ] ?? new object[0, 0]; if (isFirstRowAsIndex) { return(GetExcelRowCollectionWithRowIndex(array)); } else { return(GetExcelRowCollectionWith(array)); } } }
private IEnumerable <string> GetColumnList(ExcelWorksheets workSheets) { var masterSheet = workSheets.FirstOrDefault(x => x.Name.Equals("Masterlist", StringComparison.OrdinalIgnoreCase)) ?? workSheets.First(); Logger.LogInformation($"Master Sheet Name [{masterSheet.Name}]\n"); Logger.LogInformation($"Master Sheet Max Row [{masterSheet.Dimension.Rows}]\n"); Logger.LogInformation($"Master Sheet Max Column [{masterSheet.Dimension.Columns}]\n"); Logger.LogInformation($"Master Sheet Cell Address [{masterSheet.Cells.Address}]\n"); var columnCount = masterSheet.Dimension.Columns; var columns = new List <string>(); for (var i = 1; i <= columnCount; i++) { columns.Add(GetCellContents(masterSheet, 1, i)); } return(columns); }
public static ExcelWorksheet GetOrAddByName(this ExcelWorksheets worksheets, string sheetName) { return (worksheets.FirstOrDefault(x => x.Name == sheetName) ?? worksheets.Add(sheetName)); }