Hi naveedraza,
There are multiple ways to do this.
- One of them is to paste the collection into an Excel and then just set the cell value for the new column as SrNo (only the column heading).
Then paste back the excel data to a collection. You now will have an empty additional column where a Calc stage will need to be used to set the values for the new column using a loop.
Alternatively you could also very well write the 1,2,3...values in the excel itself and then paste the entire sheet to a collection and then nothing more to do further.
To increment the values in the Excel itself you can follow the below steps
i. Paste the collection to Excel
ii. Use Set cell value action and set the column heading as SrNo
iii. Use Set cell value action and set the value in C2 as 1
iv. Use Set cell value action and set the value in C3 as "=$C2+1"
iv. Use Copy Paste Worksheet Range action and copy from C3 to "C"& [LastRow] where LastRow is derived from Get Number of Rows action of Excel VBO.
No loop involved anywhere and the collection will be ready when this sheet is pasted into a collection.
View attachment 1530602615217.png
- Another option is to have a new Collection in Blue Prism with just one hard coded column heading as SrNo.
Then use a loop counter and increment the values till the number of rows in the other collection (there is an action to get the number of rows in the Collection VBO - not the Collection Utility VBO).
Once the new collection is ready use Merge collection with input as Collection 1 and 2, but the output allows only in a new third collection with all columns and data of 1st collection along with SrNo column and its incremental values.
- You can also write a Code stage to loop through the collection and add the column and its values from the Code itself. There are some Collection related Code on this forum in C# which you can take a look at and directly use it in C# or convert it to VB.net code if needed.
- The ROW function of Excel can also be made use of.
Just set this formula in C2 as "=ROW($A1)"
and do a copy paste from C2 till last row as explained above.
No looping involved particularly useful when large data is involved.
View attachment 1530603296590.png
You can do it in multiple ways depending on how large or small your data is.