Type Conversion in For Each Row

Hi,

I’m extracting data from an excel file to a data table and reading each element in the row using for each row and reading row item using get row item. When I run the code I get this error

Message: StringConverter cannot convert from System.Double.

Exception Type: NotSupportedException

System.NotSupportedException: StringConverter cannot convert from System.Double.
at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.StringConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at UiPath.Core.Activities.GetRowItem.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Can some please help me with this?

Thanks in advance!

Hi @ashoks93

I think Excel read activities automatically detect the type of data in the cells. If it is a number, it will create a DataTable column with doubles.
If you then try to process them as strings, it will throw an error.

I solved it for my Excel input files by converting all Excel data to text.

Change get row item variable type to double or generic

You can also convert String variable to Double,
Use following to do that,
Convert.ToDouble(“string variable”)

Cheers,
Pankaj

Hi,

Thanks for sharing your experience.

I tried that but still its not working for me.

I’m uploading the sample files.

Thanks!

HI,

I have a uploaded a sample files that I’m working on. Can someone help me with this?

Thanks in advance!

Sample Input File.xlsx (8.7 KB)
Main.xaml (9.8 KB)

Hi @ashoks93

Here is a solution, without changing anything in the xaml file. You need to convert the numbers to actual text. The fastest way is to select your column with numbers and do these steps. I tested it on your file and it worked fine :slight_smile:

Open your Excel and do those steps to convert the numbers to the actual text :slight_smile:

  1. image
  2. image
  3. image
  4. image
1 Like

another approach but, that’s way too much for a single conversion

This answer from @andrzej.kniola is a good way to understand that generic can be used for primitive types.

regards

Wow, it works perfectly!

1 Like