Hi,
Thanks for the sample project and template file.
I have evaluated your scenario/ case using your sample project with the template file. Well, there is an issue with your code segment that you using.
Please change your code segment:
i.e.,
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[sheetName];
int i = worksheet.Cells.Rows.Count;
int j = worksheet.Cells.Columns.Count;
//Exporting the contents of rows and columns starting from 1st cell to DataTable
DataTable stringdataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.Columns.Count, true);
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.Columns.Count, true);
to:
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[sheetName];
int tRows = worksheet.Cells.MaxDataRow +1;
int tCols = worksheet.Cells.MaxDataColumn +1;
//Exporting the contents of rows and columns starting from 1st cell to DataTable
DataTable stringdataTable = worksheet.Cells.ExportDataTableAsString(0, 0, tRows, tCols, true);
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, tRows, tCols, true);
…
it would work fine. Please use Cells.MaxDataRow and Cells.MaxDataColumn attributes instead which give the farthest row and column indexes accordingly.
Let us know if you still have any issue.
PS. I noticed you also included your license file in the project archive. For security concerns, please first remove the project attachment from your post (in the thread) while edit, remove the license file from the project archive and re-archive it and then re-add/ attach the project to your post again. We appreciate your cooperation in this regard.
Thank you.