@@ -22,7 +22,7 @@ public static class ExcelWorksheetExtensions
2222 /// <returns></returns>
2323 public static ExcelAddress GetDataBounds ( this ExcelWorksheet worksheet , bool hasHeaderRow = true )
2424 {
25- ExcelAddressBase valuedDimension = worksheet . GetValuedDimension ( ) ;
25+ ExcelAddressBase valuedDimension = worksheet . GetValuedDimension ( ) ?? worksheet . Dimension ;
2626
2727 if ( valuedDimension == null )
2828 {
@@ -43,7 +43,17 @@ public static ExcelAddress GetDataBounds(this ExcelWorksheet worksheet, bool has
4343 /// <param name="worksheet"></param>
4444 /// <param name="hasHeaderRow"></param>
4545 /// <returns></returns>
46- public static ExcelRange GetExcelRange ( this ExcelWorksheet worksheet , bool hasHeaderRow = true ) => worksheet . Cells [ worksheet . GetDataBounds ( hasHeaderRow ) . Address ] ;
46+ public static ExcelRange GetExcelRange ( this ExcelWorksheet worksheet , bool hasHeaderRow = true )
47+ {
48+ ExcelAddress dataBounds = worksheet . GetDataBounds ( hasHeaderRow ) ;
49+
50+ if ( dataBounds == null )
51+ {
52+ return null ;
53+ }
54+
55+ return worksheet . Cells [ dataBounds . Address ] ;
56+ }
4757
4858 /// <summary>
4959 /// Extracts an ExcelTable from given ExcelWorkSheet
@@ -82,7 +92,9 @@ public static ExcelTable AsExcelTable(this ExcelWorksheet worksheet, string tabl
8292 }
8393 }
8494
85- worksheet . Tables . Add ( worksheet . GetExcelRange ( false ) , tableName ) ;
95+ ExcelRange dataRange = worksheet . GetExcelRange ( false ) ?? worksheet . Cells [ 1 , 1 , 1 , 1 ] ;
96+
97+ worksheet . Tables . Add ( dataRange , tableName ) ;
8698 worksheet . Tables [ tableName ] . ShowHeader = hasHeaderRow ;
8799
88100 return worksheet . Tables [ tableName ] ;
@@ -358,13 +370,13 @@ public static ExcelWorksheet DeleteColumns(this ExcelWorksheet worksheet, string
358370 }
359371
360372 /// <summary>
361- /// Checks and throws if column value is wrong on specified index
373+ /// Checks and throws the <see cref="ExcelValidationException"/> if column value is wrong on specified index
362374 /// </summary>
363375 /// <param name="worksheet"></param>
364376 /// <param name="rowIndex"></param>
365377 /// <param name="columnIndex"></param>
366378 /// <param name="expectedValue"></param>
367- /// <param name="exceptionMessage">The {columnIndex}. column of worksheet should be '{ expectedValue}'. </param>
379+ /// <param name="exceptionMessage">Custom exception message with format parameters: columnIndex, expectedValue</param>
368380 public static void CheckAndThrowColumn ( this ExcelWorksheet worksheet , int rowIndex , int columnIndex , string expectedValue , string exceptionMessage = null )
369381 {
370382 if ( ! worksheet . GetColumns ( rowIndex ) . Any ( x => x . Value == expectedValue && x . Key == columnIndex ) )
@@ -379,7 +391,7 @@ public static void CheckAndThrowColumn(this ExcelWorksheet worksheet, int rowInd
379391 }
380392
381393 /// <summary>
382- /// Checks and throws an exception if the worksheet has any formula
394+ /// Checks and throws the <see cref="ExcelValidationException"/> if the worksheet has any formula
383395 /// </summary>
384396 /// <param name="sheet"></param>
385397 /// <param name="withMessage"></param>
@@ -392,7 +404,7 @@ public static void CheckAndThrowIfThereIsAnyFormula(this ExcelWorksheet sheet, s
392404 }
393405
394406 /// <summary>
395- /// Checks and throws if header columns does not match with ExcelColumnAttribute
407+ /// Checks and throws the <see cref="ExcelValidationException"/> if header columns does not match with properties of object
396408 /// </summary>
397409 /// <typeparam name="T"></typeparam>
398410 /// <param name="worksheet"></param>
0 commit comments