How to remove row with specific entire row based on condition

We have one Automation cases ,we need to remove certain rows from our excel sheet (e.g. “Page: 2 >”) and save the data in same excel sheet . Our excel sheet don’t have header so we are unable to do through remove data row activity .

Please advice…

image

Hi @Krishnakumar_Vasudevan ,

Assuming that Datatable is read without Add Headers enabled and that the condition for removal of rows is if first column contains value as Page :.

We can then check with the Filter Datatable activity with the below Configuration :
image

If this is not possible, do let us know why so that we can arrive to a different logic.

Hi @Krishnakumar_Vasudevan

How about the following?

Hope this helps!!

Hope the below steps would help you resolve this

  1. Read the excel with READ RANGE activity where disable ADD HEADERS property
    And get the output as dt

/. Now use a assign activity to filter out the datatable

dt = dt.AsEnumerable().Where(Function(a) NOT a(0).ToString.Contains(“Page”)).CopyToDatatable
  1. Then use a OUTPUT DATATABLE activity and pass dt as input and get output as string variable named strdt

  2. Just put an Assign activity with the output variable from Output DataTable like this

strdt = strdt.Remove(0, MyDataTableText.IndexOf(Environment.NewLine)+2)
  1. Use a GENERATE DATATABLE activity and pass string variable strdt as input and get output as dtfinal where disable this property Use First Row as Column Headers

https://docs.uipath.com/activities/other/latest/workflow/generate-data-table

  1. Use this dtfinal in write range activity with Add Headers disabled

Cheers @Krishnakumar_Vasudevan

Hi @Krishnakumar_Vasudevan

Certainly we can do this using LINQ, here are the steps.

  1. Read the excel with READ RANGE activity where disable ADD HEADERS property
    And get the output as dt_Input.

  2. Create a new datatable name dt_New variable and initialize it with ‘New Data table’ in the default value.

  3. Now use a assign activity to filter out the datatable using LINQ as below:

dt_New = (
From row In Dt_Input
Where Not row(0).ToString.Trim.ToLower.Contains(“page”) And Not row(1).ToString.Trim.ToLower.Contains(“page”) And Not row(2).ToString.Trim.ToLower.Contains(“page”)
Select row
).CopyToDataTable”

PFB the screen shot

  1. Use a write range activity to write the dt_New to the same excel or in a different excel/Sheet.

Thanks,
Biswajeet

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