How to add a serial number column to excel

Hi ,

I have a excel with many columns and i want to add a column whose values should be
1
2
3
4
5
6 so on.
can someone suggest

1 Like

Using LinQ.

  1. Read Excel to datatable
  2. Add Column and Assign Values using LinQ
  3. Write to xlsx, or csv.

what is linq

Please go thru below for reference only.
https://www.dotnetperls.com/linq

1 Like

otherthan that we have any method it is just adding a column to an excel by using write cell activity with a series of numbers

Using For each datatable → auto increment value and assign it to row/column index.
Iteration will be more here instead.

thing is i got the output but instead
1
2
3
4
5
i got as
0
1
2
3
4
5

it should start from 1 not from 0

1 Like

Change the assign with: ((From dr As DataRow In dtData Where (Convert.ToInt32(dr(“ID”))+1) = id Select Convert.ToString(dr(“Role”))).ToArray()) and the id will start from 1

4 Likes

how are you using this LINQ query?
Are you using via any specific activity?

How it works even i tried, it is not providing proper output. Could you please provide sample solution?

Use for each row data table activity

inside in assign use[ newDt.Rows(index).Item(“State Number”)]=index+1].
Here new Dt =my data table
index= Variable type int32 and put default value as 1.
State Number=My column Header Name where i need to increment the num from 1

and also mention in for each data table out put as “index”

Thanks
Someswaran