コード例 #1
0
        public List <Person> TranslateExcel(string targetWS)
        {
            ExcelWorksheet ws     = worksheets.FirstOrDefault(p => p.Name == targetWS);
            List <Person>  result = ParseData(ws);

            return(result);
        }
コード例 #2
0
ファイル: ExcelImportHelper.cs プロジェクト: HeHang0/MyTools
 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));
             }
         }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public static ExcelWorksheet GetOrAddByName(this ExcelWorksheets worksheets, string sheetName)
 {
     return
         (worksheets.FirstOrDefault(x => x.Name == sheetName)
          ?? worksheets.Add(sheetName));
 }