Split Table

How can i split columns of table. ex. table have 10 colums i want 5 colums in one 5 in other table.

Hi @Shubham_Kinge

you can use the below code
Assuming that you have a datatable with the 10 columns stored called dtInput

dtFirst5Columns Type DataTable

dtInput.DefaultView.ToTable(False,{"Column1", "Column2", "Column3", "Column4", "Column5"})

dtLast5Columns Type DataTable

dtInput.DefaultView.ToTable(False,{"Column6", "Column7", "Column8", "Column9", "Column10"})

Remember to replace each “ColumnX” value as your datatable column names

Regards!

1 Like

@Shubham_Kinge

Another method…

Use filter datatable and in columns give the column names you want

Cheers

1 Like

Hi @Shubham_Kinge

  1. Use a component from the UiPath Marketplace called Data Table Split by Column Names. This component receives a DataTable and an array of column names from the DataTable and creates 2 new DataTables, one containing the input columns and the other one containing the remainder of the columns

Check out this Link

  1. Use Filter Data Table activity or Select method to filter the input DataTable by column names or values and create different output DataTable. You can then write the output DataTable in different Excel sheets or files.

Regards
Gokul

1 Like

HI @Shubham_Kinge

If you know about the column name in table you can use 2 filter datatable and in filter wizard goto output columns and add the 5 columns you want in table 1

Same like for another table in another filter datatable

Regards
Sudharsan

1 Like

Hey @Shubham_Kinge

dtOutVar = dtInVar.DefaultView.ToTable(False,{“Col1”, “Col2”, “Col3”, “Col4”, “Col5”})
To get as it is
dtOutVar = dtInVar.DefaultView.ToTable(True,{“Col1”, “Col2”, “Col3”, “Col4”, “Col5”})
To remove duplicate rows
Same to separate from 6 to 10 th columns …

Cheers

Hi @Shubham_Kinge ,

Maybe a dynamic way. Although the Datatables will be stored in an Array :

  1. Firstly, Get the column names from the Datatable, say NormalDT. We can do so using the below expression :
columnNames = NormalDT.Columns.Cast(of DataColumn).Select(Function(x)x.ColumnName).ToList

Here,columnNames variable is of the type List (Of String)

  1. Next, we can use the below Expression to Group Every 5 columns and get the Datatable for it :
DTarray = (From i In Enumerable.Range(0,CInt(Math.Ceiling(NormalDT.Columns.Count/5))).Select(Function(x)x*5)
Select NormalDT.DefaultView.ToTable(False,columnNames.Skip(i).Take(5).ToArray)).ToArray

Here, DTarray is of the type Array of Datatable

Debug Panel :
image

@Sudharsan_Ka @Gokul001 @fernando_zuluaga @Anil_G
Column names are not same and 47 colums are there i can not add one by one. i need first 3 in different and remaining are in different dt.
ive done it using the read range activity.

  1. read all range store the count of rows - Rows_Count
  2. Read next table as - providing range as “A1:C:”+Row_Count
  3. read ext table as - providing range as “D1:BM:”+Row_Count
    Thanks For support.
1 Like

@Shubham_Kinge

One more way could have been to add first 3 column indexes and select keep once and remove once after reading

Happy automation

Cheers

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