Need help with Dynamic Excel Data updation

I need help with a logic to enter some data into datatable.I have a list(of string) that would be dynamic. I need to enter all the list values to to datarow in a datable. So first image would consist of already existing data

as input . And I want the string contents in my list to be added with seperate header along with the data in result . Second image would be result. Header Value 1 should be the first list value and so on. Also this list would be dynamic so I need to add data and Header for the list values i get. Can i get a help on this? Thanks!!!


Hi @Tushar_Karkera

Should the header names just be “Header 1”, “Header 2” or where to you get them from?

If the statement above is true, then you could set it up as follows:

  • For Each item in List (save index as variable int_index in properties).
  • Add Data Column to datatable (Column Name = "Header "+int_index.ToString)
  • Assign dt_Datatable.Rows(0)("Header "+int_index.ToString) = item

Regards
Soren

1 Like

Hi @Tushar_Karkera

Create the DataTable with fixed columns first, then loop through the List(Of String) and dynamically add columns using add data column. After adding the columns, create a new DataRow, assign existing data to fixed columns, and assign each list value to its corresponding dynamic column using index-based mapping, then add the DataRow to the DataTable.

Happy Automation

1 Like

Hey @SorenB Header. This Header data I am assigning a fixed value with counter variable. But I need the list(string) values to be added in datarow. Thanks for this solution. I will try this and let you know.

1 Like

Hi @prashant1603765 Thanks for the solution.I will try this and let you know.

1 Like

Hi @Tushar_Karkera

  1. Loop through your “List(Of String)” and use “Add Data Column” to create columns like:
    "Header " + (index+1).ToString
  2. Create a new row:
    newRow = dt.NewRow()
  3. Set fixed columns:
    newRow(“Name”) = “Test”
    newRow(“Department”) = “Test”
  4. Loop through the list again and assign:
    newRow("Header " + (index+1).ToString) = item
  5. Use “Add Data Row” to add “newRow” to “dt”.