Rearranging columns in a DataTable

Hi,

I need to change the format of a DataTable by rearranging columns and including blank columns in-between. Can you help help me the process to do so.

PFA the old_csv and preferred_csv.

Hi @shrayud !
I don’t know why but I have an error when i try to unzip your folder.
Anyway, to add columns, you can use “Add DataColumn” activity and precise the index you want the column to be added and give it a dummy columnName
To change the position of the columns, I use an artisanal way: by using Filter datatable activity, and add all the columnNames at the column field in the wanted order. I am sure there is a better way, but for the time being it’s a clue :joy:
image

1 Like

For Rearranging the table columns you can use Set Ordinal method in the invoke code activity using the below code:

Dt.columns(“yourcolumnname”).setordinal(5)

I just gave 5 as an example here.

1 Like

Hey thanks:

error BC30451: ‘dtCheck’ is not declared. It may be inaccessible due to its protection level. At line 1

This error is coming. dtCheck is my datatable

Oh sorry…you have to use Invoke Method activity.

I will share the sample once I am back.

hi @shrayud … Please find the sample below…

My Input:(Status column is 2 i.e. index 1 (index starts of 0)

image

Invoke Method ( here I gave, so that Status column will be moved to 0)

You can see the output in my first screenshot.

Hope this helps…

2 Likes

Thanks,

I also need to delete few columns like in your case:

[ID Status Value Date] It needs to be

[ID Date Value] I want to remove status column while rearranging; can I do so using Invoke activity

@shrayud - You can use “Remove DataColumn” Activity and give ColumnIndex as 1 (in your case)…

or you can use…“Insert\Delete Columns” inside excel app scope …and choose remove in the property and give the column positions…

1 Like

Thanks

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