I need to replace Text in excel . There are 32 colums with header and 1000+ rows with values. If Value contains "Milestone" i need to replace with "Yes"

I need to replace Text in excel . There are 32 colums with header and 1000+ rows with values. If Value contains “Milestone” i need to replace with “Yes”.
Complete Datatable i need to find and replace for following.

can some one help me with solution .

as it is an optimistic approach

(From r In dtData.AsEnumerable
let ra = r.ItemArray.Select(Function (x) x.ToString.Trim.Replace(“Milestone”,“YES”)).toArray()
Select dtCorrected.Rows.Add(ra)).CopyToDataTable()

1 Like

I am using C#. i tried this code but getting errors

@supermanPunch bro any help

what if you simply try find&Replace within Excel?

1 Like

Hi @MitheshBolla ,

You could try and use the Below Expression in an Assign Activity, it is a Conversion of the Linq in vb.net to c# :

OutputDT = DT.AsEnumerable().Select(c=>OutputDT.Rows.Add(c.ItemArray.Select(x=>x.ToString().Trim().Replace("Milestone","YES")).ToArray())).CopyToDataTable()

Here DT in the Input Datatable, OutputDT is the Datatable variable which needs to be Initialised with the Clone of Input Datatable DT before using the above Expression.

image

For this Particular Case, we could also Try with a Regex/String Replace Method, where we First Convert the Datatable to String, Replace the String "Milestone" with "Yes", then use Generate Datatable Activity to Convert the String back to a Datatable.

As it is a Mass Update, it shouldn’t be a problem.

1 Like

for c# it is usually to use x => x syntac for the VB.Net Function (x) x equivalent
we also have to respect the propert syntax (case sensitive, () cannot be ommited)…
On the end we do close with a ;

It could be the case that there is a confusion for current UiPath .Net Infrastructure and LINQ Query syntax.

Which error you do get for which adapted LINQ?

1 Like

with which activity it is possible?

Bro thanks a lot . This worked.

If there are 2 to 4 replaces that is

“MilestoneFailed” as “No”

Blanks as “NA”

same code i need to assign 3 times or add these two changes in single assign?

OutputDT = DT.AsEnumerable().Select(c=>OutputDT.Rows.Add(c.ItemArray.Select(x=>x.ToString().Trim().Replace(“Milestone”,“YES”).Replace(“MilestoneFailed”,“No”)).ToArray())).CopyToDataTable().

for multiple replace conditions how to write bro

@MitheshBolla , Try using the Milestone failed as the First Replace and then just the Milestone like below :

DT.AsEnumerable().Select(c=>OutputDT.Rows.Add(c.ItemArray.Select(x=>x.ToString().Trim().Replace(“MilestoneFailed”,“No”).Replace("Milestone","Yes")).ToArray())).CopyToDataTable()

Let us know if this doesn’t work.

1 Like

Thanks A lot bro

1 Like

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