Add maxColumns and removeEmptyRows parameters to ExcelHelper.ToDataTable()
Ninjanaut opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
Many times ExcelHelper.ToDataTable()
returns DataTable
like
- The issue is probably caused by that cells has applied formatting, but in practice users might be loading thousands of unnecessary columns and rows which also has performance impact.
or it does not load DataTable
at all, because of weird System.IndexOutOfRangeException
, when cell count is for example 5, but row count is 4 (I do not know how to create such an excel, but I attach an example with that exception
ExcelWithOutOfRangeException.xlsx
Describe the solution you'd like
So I thought an elegant solution would be to extend method signature of ExcelHelper.ToDataTable()
with maxColumns and removeEmptyRows like
public static DataTable ToDataTable(byte[] excelBytes, ExcelFormat excelFormat, bool removeEmptyRows = false, int? maxColumns = null)
Describe alternatives you've considered
Removing columns and rows can be done later when DataTable
is already loaded (except that case throwing System.IndexOutOfRangeException
) but it requires unnecessary additional loop through DataTable
and is so common operation that it would be great to have it in one method and not have to write it separately.
Additional context
if there will be an interest in these features, I'll be happy to send a pull request.
@Ninjanaut, great thanks for your reporting and your valuable thoughts, sounds great to me, and it would be great if you could make a PR to fix it