I have an excel with 45 columns but I want to keep only 13 columns

Hello Team,

I have an excel with 45 columns.

I want to keep only 13 columns.

These 13 columns can be or cannot be in that excel.

But if they are present they should be kept else not.

Looking for suggestions on this.

Regards,
Sateesh.

@sateesh.thandra

Welcome to the community

  1. use excel file
  2. for loop with Enumerable.Range(0,45).ToArray as the input for for loop to loop 45 times…or use for number of times and select 45
  3. Inside loop use get cell activity with cell number as Excel.Sheet("Sheetname").Cell(UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(45-currentitem) + "1") …this will get the cell value into variable
  4. Now use if condition to check arr_of_ColumnName.Contains(str_returnedvalue)
  5. on then side delete column and on else side do nothing

cheers

Create an array of the names of the columns you want to keep. Loop through all the column names that exist in your datatable and if the current column name doesn’t exist in the “keep these” array then delete it.

Use read range and after that use filter datatable in that u will have a option which column u can keep

Except he can’t hard code the columns in Filter Data Table because they might not all be there so it would fault.

1 Like