How can add Column After Or Before Specific Column

I want to add Col before another Col. I use Invoke Method, but don’t know use Parameters ?. Please help me

DT_Input.Columns(“AddCol”).SetOrdinal(DT_Input.Columns(“AddCol2”).Ordinal)

@anh.nguyen ,
Please refer this thread this might help you.

Regards,

1 Like

@anh.nguyen

Please check this Article with detailed steps

cheers

1 Like

Because the specific column is dynamic so I don’t know index just know header col.

Hi @anh.nguyen

You can insert column at a specific place by using insert column activity. But this is an excel activity.

I dont know what place will add col, just can add New Column before specific Column (know header Column)

Hi,

The following is a sample which add new column before another column named “colX”.
Hope this helps you

Sample20230407-8L.zip (4.8 KB)

Regards,

2 Likes

You can find the index index of the column you know by using:

dt.Columns.IndexOf(“ColName”)

Then you can add data column and set it to the index you want by using set ordinal function in invoke method.

Hope it helps.

Regards,
Harshith

1 Like

It worked, but have error

You can also give column header name. You can mention the specific column name then there is an option which to set where you need to add after or before.

Hi,

We cannot add new column named “AddCol” because it already exists. (Column name must be unique)
Do you want to create table which has 2 or more same name columns?

Regards,

Hi,
there is no AdCol column at first. after run your code it added AdCol column before QUANTITY (PC/PCS)> if I test change name, still this error

Hi,

Can you share content of the datatable at Local panel when workflow stops due to exception?

Regards,

1 Like

hi

That column is already present.

Are you using add datacolumn inside a loop? If yes, it is giving error in 2nd iteration.

1 Like

Oh yeah in loop. Thank all so much :slight_smile:

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