Esempio n. 1
0
        public static IEnumerable <string> ColumnHeaders(this OfficeOpenXml.ExcelWorksheet worksheet)
        {
            List <string> headers   = new List <string>();
            int           maxColumn = worksheet.MaxColumnNumber();

            for (int columnNumber = 1; columnNumber < maxColumn; columnNumber++)
            {
                headers.Add(worksheet.GetValue(1, columnNumber).ToString());
            }
            return(headers);
        }
Esempio n. 2
0
        public static int MaxRowNumber(this OfficeOpenXml.ExcelWorksheet worksheet)
        {
            // find the maxRow
            int maxRow    = 0;
            int maxColumn = worksheet.MaxColumnNumber();

            for (maxRow = 1; maxRow <= 999999; maxRow++)
            {
                var nextTwo = worksheet.Cells[maxRow + 1, 1, maxRow + 2, maxColumn];

                // if next two rows contain all empty values then we are done
                if (nextTwo.All(v => string.IsNullOrEmpty(v.ToString())))
                {
                    break; //out
                }
            }
            return(maxRow);
        }