Cannot assign from type 'System.String' to to type 'UiPath.Excel.ExcelValue'

image
I frequently get this error when updating Excel. I think it is not a true error but an issue with the compiler. If I assign a complex string like this

CurrentRow.ByField(“Address”) = jsonObj(“Parcel”)(“propertyAddress”).ToString.Trim

I get this error. But if I assign the right side first to a string var and then assign it to the left it compiles and runs fine.

strVar = jsonObj(“Parcel”)(“propertyAddress”).ToString.Trim
CurrentRow.ByField(“Address”) = strVar

However, later the compiler may catch this and call the same error. If I recreate the ‘multiple assign’ activity identically, it compiles.

Adding a .toString() to the strVar sometimes helps though seems odd.

CurrentRow.ByField(“Address”) = strVar.toString

It is a hassle to keep having to rewrite the code. Is there a solution?

Hi @Phil_Kelsey

Try this:

CurrentRow("Address") = jsonObj("Parcel")("propertyAddress").ToString.Trim

Hi @Phil_Kelsey

Can you try the below syntax:

CurrentRow.ByField("Address") = New UiPath.Excel.ExcelValue(jsonObj("Parcel")("propertyAddress").ToString().Trim())

Hope it helps!!

Hi @Phil_Kelsey

CurrentRow.ByField(“Address”) = CStr(jsonObj(“Parcel”)(“propertyAddress”).ToString.Trim)

Hope it helps!!

that way does seem to compile. I will post back if it appears to be a lasting solution. I appreciate your help.

Hi @Phil_Kelsey

CurrentRow(“Address”) = jsonObj(“Parcel”)(“propertyAddress”).ToString.Trim

@Phil_Kelsey

The error indicating that you can directly assign the string value(jsonObj(“Parcel”)(“propertyAddress”).ToString.Trim) to ExcelValue(CurrentRow.ByField(“Address”))

So you can either change the to ExcelValue to string value by removing byfield(CurrentRow(“Address”)) or convert the string value to excel value as @Parvathy suggests

1 Like

@Phil_Kelsey

try this

CurrentRow("Column").StringValue = StringVariable

Or

CurrentRow.ByField("Column").StringValue = StringVariable

For your case CurrentRow.ByField("Column").StringValue = jsonObj("Parcel")("propertyAddress").ToString.Trim

Hope this helps

cheers

This issue comes due to the Different type of data types we are using to set a value to different types of data types, to solve this we need to convert that value or type cast the value to the same data type.

Supposed I have taken the String URL = "https://mukesha.com/" if i try to allocate this to int data type it will not work but URL = "19191" has some number then it will going to work.

Use below code

CurrentRow.ByField("Address") = New UiPath.Excel.ExcelValue(jsonObj("Parcel")("propertyAddress").ToString().Trim())

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.