Example #1
0
        public static ExelSheet[] LoadSheets(Workbook workbook, int count = 0, Action <int> progressReport = null, bool deleteEmptyRows = true)
        {
            var result = new List <ExelSheet>();

            //var totalRowsCount = 0;
            //var loaded = 0;
            //totalRowsCount = workbook.Worksheets.Cast<Worksheet>().Select(i => i.Cells.Rows.Count).Sum();

            Helpers.PercentageProgress prg = new Helpers.PercentageProgress();
            prg.Change += (s, e) =>
            {
                if (progressReport != null)
                {
                    progressReport((int)e.Value);
                }
            };

            foreach (var sheetItem in
                     workbook
                     .Worksheets
                     .Cast <Worksheet>()
                     .Where(s => s.Cells.Rows.Count > 1)
                     .Select(s => new
            {
                Sheet = s,
                ProgressInfo = prg.GetChild()
            })
                     .ToArray()
                     )
            {
                ExelSheet sht = new ExelSheet()
                {
                    Name = sheetItem.Sheet.Name
                };

                sht.Rows.AddRange(
                    LoadRows(sheetItem.Sheet, count, new Action <int>((i) => { sheetItem.ProgressInfo.Value = i; }), deleteEmptyRows)
                    );
                if (sht.Rows.Count > 0)
                {
                    result.Add(sht);
                }
            }

            return(result.ToArray());
        }
        public static ExelSheet[] LoadSheets(Workbook workbook, int count = 0, Action<int> progressReport = null, bool deleteEmptyRows = true)
        {
            var result = new List<ExelSheet>();
            //var totalRowsCount = 0;
            //var loaded = 0;
            //totalRowsCount = workbook.Worksheets.Cast<Worksheet>().Select(i => i.Cells.Rows.Count).Sum();

            Helpers.PercentageProgress prg = new Helpers.PercentageProgress();
            prg.Change += (s, e) =>
            {
                if (progressReport != null)
                    progressReport((int)e.Value);
            };

            foreach (var sheetItem in
                            workbook
                            .Worksheets
                            .Cast<Worksheet>()
                            .Where(s => s.Cells.Rows.Count > 1)
                            .Select(s => new
                            {
                                Sheet = s,
                                ProgressInfo = prg.GetChild()
                            })
                            .ToArray()
                            )
            {
                ExelSheet sht = new ExelSheet() { Name = sheetItem.Sheet.Name };

                sht.Rows.AddRange(
                    LoadRows(sheetItem.Sheet, count, new Action<int>((i) => { sheetItem.ProgressInfo.Value = i; }), deleteEmptyRows)
                    );
                if (sht.Rows.Count > 0)
                    result.Add(sht);
            }

            return result.ToArray();
        }
Example #3
0
 protected string GetNearestSubheader(ExelSheet sheet, int rowIndex)
 {
     var result = string.Empty;
     if (sheet.SheetHeaders.Subheaders.Count > 0)
     {
         var header = sheet.SheetHeaders.Subheaders.Where(h => h.RowNumber <= rowIndex).LastOrDefault();
         if (header != null)
         {
             result = header.Header;
         }
     }
     return result;
 }