ExportDataTable method fails to export if one of the column contains mixed type data

Hi There,



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?



Thank you,

Bhavin

Hi Bhavin,

Thanks for your posting and using Aspose.Cells.

When
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:

C#


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);

Hi Bhavin,

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.

Hi Bhavin,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.1.0.3 and let us know your feedback.

Hi,


And please use ExportTableOptions.CheckMixedValueType attribute in the new fix/version: Aspose.Cells for .NET v8.1.0.3.

Thank you.