Datatable write next row


#1

Hi,

Seems like there is no simple example about this task:

I want to put a list of string in a col in different rows (next row). e.g. {1,2,3,4,5} into column A
A
1
2
3
4
5

I have created a really simple xaml as an example. Could you help? Thanks
I know I need to use for each row and n = n +1, but things are just not in the right place.

a.xaml (15.4 KB)

thanks!
Lavina


How to write variable value in next available cell in an excel column?
#2

To add a row to a DataTable you can use ‘Add Data Row’ activity. Check this,

a.xaml (13.4 KB)

Let me know if it helps.

Thanks
Rammohan B.


#3

Hi @Rammohan91,

Thanks for your response! I have 2 questions.

  1. So I actually have 2 arrays which have to be inserted in 2 separate columns. In your solution, I can’t find the place to specify the column. I may have missed it. Can you point me to it please?

  2. Do you happen to know what the Column Object in the Add data column for?

“A DataColumn object that is to be appended to the column collection of the DataTable. If this property is set, all of the properties under the Options category are ignored” I still don’t understand when to use it…

Thanks a lot!

Regards,
Lavina


#4

I don’t see a second array under your workflow. There was only one ‘ites’ which has value {‘abc, cde, def’}.

The problem with your workflow was that you were using ‘For Each’ inside a ‘For Each Row’. Since you just created an empty datatable and your datatable doesn’t have any value to loop through it, it will thrown an error.

In most of the cases you use ‘For Each Row’ on a datatable to retrieve/update a value of a particular item of a row.

You can create a DataColumn Variable and assign it to the Add Column Activity. If you add a column by DataColumn object you cannot specifically indicate the ‘ColumnName’ property. I believe in most of the cases the column is captured from a different datatable and it may already have those ‘Options’ properties due to which the ‘Options’ property from the ‘Add Data Column’ property will be ignored.

Thanks,
Rammohan B.


#5

Hi @Rammohan91,

sorry for the confusion - yes there is only one array in my test xaml. But in the real life situation, I actually have two arrays and each array has to be in a different columns in excel. I am just wondering if there is a spot where I can specify by column name/column index. Also, thanks for your respond on the data column.
Thank you!

Lavina


#6

It may not be an efficient solution and may prone to errors if you have different number of items within both the array.

TwoArrayToRow.xaml (9.6 KB)

Thanks,
Rammohan B.


#7

Hi @Rammohan91,

Awesome! Thanks :slight_smile: the length of my arrays have to be the same so I have an if statement for it. Thank you very much!

Regards,
Lavina