Input String was not in correct format.Expected type is double

Hi,

I am getting an exception "Input String was not in correct format "Couldn't ' asdf '" in Column3 column .Expected type is double"

When i am trying to export data from the excel sheet to a datatable using worksheet.Cells.ExportDataTable.

I am getting the above exception,what i noticed is the Column3 i.e C1 in excel has a integer (100), all the other colums are string below that. when i put any string value in (Column3 i.e C1 in excel ) it is working.

Is this a generic problem what i am faceing, or anything specific to Aspose. please give me a solution how to solve this.

Thanks & Regards,

Babu Benny

Hi,

Please download and try the latest version:
Aspose.Cells
for .NET v7.1.1.5

and let us know if it works fine.

If the problem recurs, then please provide us your code and source xls/xlsx files if any to replicate this problem.

We will help you asap.

Hi,

Well, Cells.ExportDataTable() method decides which data type would be setup for particular column in Excel sheet. By default, it is based on the first value (normally) in the column, if it is string value, then the DataColumn would have string data type for the data table, if it has numeric value, the numeric data type would be taken for the column. Please make sure that if it goes in that way.

Due to what is discussed above, you are getting the exception regarding your variant data in different rows in a column. I think for your case, you should define your desired DataTable based on your desired columns and specify your desired data types. Then use the relevant ExportDatatTable() overloaded version to store the data into it.

See the sample code segment below:
e.g

DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof(string));
dt.Columns.Add("column2", typeof(string));
dt.Columns.Add("column3", typeof(string));
dt.Columns.Add("column4", typeof(double));
dt.Columns.Add("column5", typeof(double));
dt.Columns.Add("column6", typeof(double));
dt.Columns.Add("column7", typeof(double));
//.............
worksheet.Cells.ExportDataTable(dt, 0, 0, 1000, true);

Alternatively, you may use ExportDataTableAsString() method, but in this case all the data would be exported as string/text.

Thank you.