Excel, Data table, For Each row

Hi Team,

I Have a data table as follows

image

How I will get the output like as

image

Kindly help me out for this solution.

Thanks in Advance

1 Like

Hi @manikandan.murugan

Try this

(From row In dt_Input.AsEnumerable()
                       Let Rowno = dt_Input.Rows.IndexOf(row) + 1
                       Select dt_Input.Clone().Rows.Add(row("Date"),Rowno.ToString)).CopyToDataTable()
1 Like

@manikandan.murugan,

Try this way.

  1. Use For Each Row in DataTable activity.
  2. Declare Output/Index variable which will hold row index it’s iterating starting with zero.
  3. Use assign activity inside loop to assign row number. Add 1 to index value as index is starting at 0.

Thanks,
Ashok :slight_smile:

1 Like

Hi @manikandan.murugan

you can try the below workflow by using the excel activities,
→ Use the Excel Process scope activity and insert the Use excel file activity inside of it.
→ Give the path of the excel file in Use excel file activity.
→ Insert the For each excel row activity inside the Use excel file activity.
→ Inside for each insert the write cell activity.
→ Give the CurrentRow.Byfield(“Row Number”) in where to write field and give CurrentIndex+1 in what to write field. Check the Auto increment option for sure.

Check the below workflow for better understanding,

Hope it helps!!

2 Likes

Thanks @ashokkarale @lrtetala @mkankatala

2 Likes

Is there any way to convert a column values (RowNumber) from string to int

Check what’s the datatype of the column RowNumber. If it’s int32 current code should work but if it’s string or object, I would suggest deleting the RowNumber column using Delete Column and add new column with same name but with In32 datatype using Add Data Column

Thanks,
Ashok :slight_smile:

1 Like

No Your Solution is perfect and it’s working,

I merged 2 data tables into a single data table. I used the following

FilterDT.DefaultView.ToTable(True, “Date”,“RowNumber”)

The duplicates are not removed as combination of string value and int. If I change the entire column values as int means I can easily remove the duplicaletes

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