Converting Output of Read Cell to String

Hey folks,

im using the Read Cell activity to get a value from an excel, save it into a variable and later post it via the Type into activity. So far it’s working great for excel cells that contain text but now I encountered one that contains a number. It seems like UIPath is interpreting the number as a double instead of a string, resulting in an exception (Message: StringConverter cannot convert from System.Double).

Is there a way to cast the output argument (Result) of the Read Cell activity into a String and assign it to my variable?
Basically looking for something like: MyVar = Converter.toString(Result)

Hi @dhyr

Yes, you can simply use this syntax:

You can use it like that directly in the Type Into activity.

Hi @loginerror and thanks for your reply.

This would include setting my variable to type “Double” right? Sadly this creates a new error in the Read Cell activity: “Option strict on does not allow implicit conversion from double to string”. No idea what “option strict on” is or why there should be an implicit conversion

Okay, I think there are three options here.

  1. You can use the Generic type variable. It is meant to automatically “adapt” the type to your needs for basic operations.
  2. You can indeed first set your type of the variable to Double and use the variable with a .ToString whenever you want to type it in.
  3. Convert the number to text directly in Excel so that UiPath activity will read it as text

This comes from the fact that Read activities apparently automatically try to detect the type of the value they are reading. I actually thought it was only the case for Data Tables, as those need their columns strictly defined upon creation. The fact that Read Cell acts the same is a bit confusing to me, but I am sure there is a logic to it as well.
Personally, I think one should be able to customize it in Properties of the activity.

Either way, I am sure it will read it as text if you convert the values to text using the “Text to Columns” trick:

And the result (note the green arrow mark):


Ok I had the message I posted in my last post was some weird error. Setting the variable to Double does work now. Thanks for your help :slight_smile:

The error about converting the Double to String was just that - your variable was of type String and the activity tried to write a Double to it.

This is why setting your variable type to Double works and removes the error :slight_smile:

No no you got me wrong there. I did set the variable type to Double and then got an error in the Activity with the text "“Option strict on does not allow implicit conversion from double to string”.

However recreating the variable fixed the issue so I guess it was some small bug within the Validation/UIPath software.

Thanks, now I got you. I’m glad it’s solved for you and hopefully the bug will get fixed :slight_smile: