ExportDataTable method is very useful method when we want to do data aggregation.
I sense that ExportDataTable method fails to export data to table when one of the column has mixed data. e.g. first few rows contain numeric and later string data.
Can you make ExportDataTable method more resilient to failure? One of the possible way is that, you convert the column to “string” data type??
e.g. ExportDataTable(bool IgnoreTypeCastError)
When IgnoreTypeCastError is true, the column which fails due to type cast error, treat that particular column as “String” and continue… Otherwise, when IgnoreTypeCastError is false (by default), the behaviour should be a Type cast error (as experienced in current versions)
Can you please please have a look at this scenario?
Thanks for your posting and using Aspose.Cells.
user does not specify the data type of columns of the datatable, we
have to determine it by the first data in this column (for performance
consideration, we cannot traverse all cells to check whether there are
multiple data types in one column).
For your situation, we think
you can manipulate the process of determining data types by yourself
and then export data to the datatable. If you know data types of those
columns in your file, you can just define column type of the datatable
with constant value. Otherwise you can check all cells or cells of first
row (depends on your business requirement) to determine the data types.
Please see the following code example:
ExportTableOptions etOpt = new ExportTableOptions();
etOpt.ExportColumnName = true;
DataTable dt = new DataTable();
dt.Columns.Add().DataType = typeof(string);
dt.Columns.Add().DataType = typeof(double);
etOpt.DataTable = dt;
cells.ExportDataTable(0, 0, 3, 2, etOpt);
Thanks for using Aspose.Cells.
As we mentioned earlier, this issue is caused by that we only check the value type of the first row data to set the column type for performance reason.
We will add a new property in ExportTableOptions to whether checking all rows to set the column type.
We have logged this issue in our database for implementation. Once, there is some fix or other update for you, we will let you know asap.
This issue has been logged as CELLSNET-42774.
Thanks for your using Aspose.Cells.
Please download and try the latest fix: Aspose.Cells for .NET v220.127.116.11 and let us know your feedback.