Add values from List<String> to datatable

I have a List in my workflow. To this list, I add values extracted from multiple webpages using Add to Collection activity.
I have to store this List to an excel file over a specified range. The Write Range activity allows datatable as input. So I thought of converting the List to a Datatable but I haven’t found any expression that satisfies this use case.

Alternatively, I thought of using foreach activity on the List and assign each item to a row or column in datatable. But the datatable is empty.
Can you guys please advise on this? If you’ve some other alternative, it is welcomed.

Note: The count of items in List is undefined can be upto n values. Please refer to the attached workflow.Converttodatatableandaddtoexcel.xaml (11.4 KB)

Regards,

You can do it in two ways @deepak.naidu,

Same as the way you tried will work, but leave it .

Simply use Excel application scope and inside that use for each activity and iterate the list you have.

Then use write cell activity to write each value to the excel. For dynamic range, declare a variable as count of type int32. Initialize it with 1. Increment its value before write cell activity and the range will be

“A” + count.tostring

1 Like

Hello @HareeshMR, Thanks for the new alternative, this seems straight-forward and the correct approach. :slight_smile:

I did as you illustrated above, but the excel loads empty which I don’t know why.
I’ve validated that the List is not empty by using foreach to print each item in the list, which returns value as expected.
For troubleshooting, I’ve attached the updated workflow. Could you please check and let me know if I’ve missed out anything.
Converttodatatableandaddtoexcel.xaml (7.8 KB)

Regards,
Deepak.

Check if you are getting values inside the for each loop using message box and your write cell activity will be like this…

image

1 Like

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