Adding Columns to a datatable

I have a workbook with 20 columns and I need to add 4 new columns at the end namely “Old Date” , “New Date” , “Match” and “Code”. The values that would go into these columns are dynamic and are stored into 4 different variables (say a,b,c and d).

I run a for each row on the datatable (say Dt) and then assign the new columns as -

new DataColumn = Dt.Columns.Add(“Old Date”, GetType (String), a)

and similarly for the other columns using variables b,c and d. I am then writing the data table into an excel. While doing that, the output column header comes as “Old Date + (the last date)” with some random long decimal numbers in all rows of that column. For the other columns, it does not even pull the data or throws a Missing Operand ‘REP’ error.

What could be the problem ? Please help.

Thanks.

1 Like

Hey @susbasu

Why you are not using Add Data Column Activity under Datatable Category for the same?

Regards,!!
AKsh

2 Likes

Hello @susbasu,

Please have a look at below picture,
create variable dt and follow a picture.

Thanks,
Pankaj

2 Likes

I have been trying to work on this example. Please find attached the code and the input excel.

I added a new column named “Locality” and tried to add values to it based on certain conditions. However, I am getting only the first value even if I run the counter.

Can you please help me know where is it going wrong ?

Thanks!

Main.xaml (19.8 KB)
Test_2.xlsx (8.6 KB)

Hi @susbasu,
I have fixed you project. I have handled by Switch activity. I have attached the Project below.

File : Adding Columns to a datatable.zip (14.9 KB)

Regards
Balamurugan

1 Like

Thanks a lot Bala! This is great!

However, this is just an example where there are 3 rows. How can we use the variable “vComment” to add values to the column when there are 3000 rows ?

Thanks!

Hi @susbasu,
I have changed a code a little without using the temp datatable. I has update with the same table. so you can use this to update more rows.

File : Adding Columns to a datatable.zip (9.5 KB)

Regards
Balamurugan

Hello , I need to add the data in a column. I have used the for each row and using get row item I am pasting the values in the excel using write cell.
It is working bt it is taking too much of time as write cell is pasting values one by one as per the loop in the column.
Do we have any other methods to do this?

Hi @Karan28,

To add column you can use the Add data column by this below link,

And use the write range to write into the excel sheet.

Regards
Balamurugan.S

1 Like

Sorry for the late reply , Thankyouuu so much

1 Like