Remove first two columns and write in to another sheet

Hi,

I have An logic to remove last two columns from excel - DT.DefaultView.ToTable(False,DT.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName).Take(DT.Columns.Count-2).toArray)

But i need to remove 1st two columns… can you please suggest me a logic for this.

Thanks,
Rishi

Hi @Putta_Sri_Sai_Rishik_Chow

To remove the first two columns from an Excel file using UiPath, you can use the following logic:

  1. Read the Excel file using the “Excel Application Scope” activity and store the output in a DataTable variable (let’s call it DT).
  2. Use the “Remove Data Column” activity twice to remove the first two columns of the DataTable. For example, if the column names are “Column1” and “Column2”, you can use the following expressions:

DT.Columns.Remove(“Column1”)
DT.Columns.Remove(“Column2”)

Note: If you don’t know the column names, you can use the column indices instead. For example, to remove the first two columns, you can use:

DT.Columns.RemoveAt(0)
DT.Columns.RemoveAt(1)

  1. Finally, write the updated DataTable back to the Excel file using the “Write Range” activity.

@Putta_Sri_Sai_Rishik_Chow

instead of Take… use Skip(2)

cheers

Hi @Putta_Sri_Sai_Rishik_Chow ,

You can use skip function instead of take to skip the number of columns you like.

Regards,

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