Insert column at first position

Hi all

I am trying to search for the code that can help me insert column at a specific position ( namely 1st ) . Now i already have an excel sheet which is not in Table format - its just a plain excel sheet . I need to insert a "U Id " column at the A position , how can i do that ?? kindly help, thanks in advance !

Hi @shaileshpathak,

Use Write Cell activity to insert the data into the Column.

Regards,
Arivu

@shaileshpathak, Two ways,

  1. Datatable Column Re-Ordering
  1. Excel - Insert Column

Regards,
Dom :slight_smile:

HI @arivu96 - I want to insert a new Column as UiD as the first column of excel, the Write Cell activity will overwrite the already existing Column Name rather than inserting a new column

Hi @Dominic - this one would insert column to an empty sheet , what if i have two columns already existing - For example my first column is EventName, second one Date . So I need to add a column before EventName - as UiD .

@shaileshpathak
You can do like this also

Add DataColumn Activity and give name UID

Then use like this
dt=dt.DefaultView.ToTable(False,“UID”,EventName",“Date”)
Now UID will become first column.

Regards,
Mahesh

3 Likes

@shaileshpathak,

NO. It does even if there is/are column(s) in it. Because we have Position property just to make it more clear where 0 indicates the Very first column and so on…

The only limitation (as far as I know) - We need a readymade TableName for your sheet :slight_smile:

Regards,
Dom :slight_smile:

@MAHESH1 - nice idea ! it works :smiley:
Thanks !

@shaileshpathak

You can try this,
dt.Columns.Add(“UID”).SetOrdinal(0)

Regards,
Mahesh