Reference "Microsoft.Office.Interop.Excel" error

Hello,
I have UiPath Studio version 2023.4.4, I installed the Microsoft.Office.Interop.Excel dependency from Microsoft but the code still does not work:

This is the code I use in an “Invoke Code” activity

I get these errors:
image

Hi @Nicollebro

You can remove the first four lines of the code as those lines represents that you should add those from Imports Panel. You need not use that in the Code. Please import those lines.

Regards

  • is the UiPath project compatibility set to Windows or Legacy?
  • referenced via Manage Packages?
  • is also UiPath.Excel.Activities referenced?

We ask these questions as:

will solve in the next step

But still there is a risk that the coded part will fail on other constraints

As alternate to handle duplicated column names have a look here

Read range excel without using first line as header line - dtData

newColNamesInfo =

(From t In dtData.Rows(0).ItemArray.Select(Function (x,i) Tuple.Create(i,x.toString))
Let t2 = If(String.IsNullOrEmpty(t.Item2.toString.Trim), Tuple.Create(t.item1, "COL"),t)
Group t2 By k=StrConv(t2.Item2.toString, VbStrConv.ProperCase).Trim.Replace(" ","") Into grp=Group
Let cg = grp.Select(Function (x,i) Tuple.Create(x.Item1, (k & "_" & i.toString).Replace("_0",""))).toList
Select cg).SelectMany(Function (x) x).OrderBy(Function (ot) ot.Item1).toList

Afterwards we are removing the first line from dtData, as we dont longer need the old header names

I answer your questions, the project is in Legacy

Yes

I stopped using the libraries in the code and imported them into the UiPath project but it still doesn’t work. :confused:

when set to Legacy, we have a chance to avoid the additional referencing to Microsoft.Office.Interop.Excel as also UiPath.Excel.Activities is already referenced

share with us always the error and what was done / the current implementation

had you a look on it? any reasons to do it mandatory in Interop code and not within UiPath / DataTable level?

I took a look to do it as you taught but it doesn’t work, I get this error: Compiler error(s) encountered processing expression “item.Item2”.
Value of type ‘String’ cannot be converted to ‘System.Data.DataColumn’.

Ensure the right Type Argument from the for each Activity.

Yes, thank you very much, this part already worked

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