Export data from Excel to datatable with unknown number of rows

I have spreadsheet where the user enters specific information and I don’t know how many rows will be enter. In the Cells.ExportDataTable, it requires you to specific the “totalrows” and “totalcolumns”. Is there a way to export the data without knowing the number of rows or possibly columns?

Hi,

Thanks for your query.

Well, you may try to use Cells.MaxDataRow and Cells.MaxDataColumn to get the farthest row index and farthest column index for your needs, see the sample code for your reference:
e.g.
Sample code:

Workbook book = new Workbook(“e:\test2\Book1.xlsx”);
Worksheet worksheet = book.Worksheets[0];
DataTable t = new DataTable();
t = book.Worksheets[0].Cells.ExportDataTable(0, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1);

Hope, this helps a bit.

Thank you.