Hello,
Thank you for contacting.
Please kindly note that the column names are used by default as field names of the DataTable when using sheet.ExportDataTable(), but the DataTable can not have the same field names. Thus, you got the error message. However, you can refer to the followng sample code to set the first row of the DataTable does not contain the column names.
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"test.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//specify the used range of the sheet
CellRange range = sheet.Range[sheet.FirstRow, sheet.FirstColumn, sheet.LastRow, sheet.LastColumn];
//the "false" is setting the first row of the DataTable does not contain the column names
DataTable dataTable = sheet.ExportDataTable(range, false, true);
Or, you can use the following code snippet to select certain columns without setting the first row of the DataTable does not contain the column names.
- Code: Select all
......
Worksheet sheet = workbook.Worksheets[0];
//select the first and second columns
CellRange range = sheet.Range["A1:B5"];
//the first "true" is setting the first row of the DataTable contains the column names
DataTable dt = sheet.ExportDataTable(range, true, true);
If there is any question, please provide your testing file to help us further look into it, you could send it to us via email(
support@e-iceblue.com).
Sincerely,
Lisa
E-iceblue support team