I have one Data table which has some values (in Value column) and from that data table I need to put those values in another excel in its columns. Check the below screenshot of the excel
So I will use for each row loop to go through the first data table and get the values and assign each value to each column of the above excel. The excel will consist only one row.
The number of rows in the data table is equal to number of columns in Excel.
Hi @Debartha_Mitra_DE
Can you please share an example of the data (using dummy data if you prefer)?
Are you looking for something like a transpose operation, where you have datatable having values in key-value pairs which you then want to put in respective columns?
Please share the structure of datatable for comparison with this excel sheet.
in the for each row create a string variable with spaces in between with all the row.item() values
within the loop use generate data table using this structured string to create a new data table for each row
Thanks for the reply, yes kind of that. Please see below screenshot for reference. This is the first excel from I am collecting the data in Datatable.
After collecting it I am going to put those data in to the respective columns in the second excel which I posted in the beginning. (similar like key value pairs)
Define: initial excel data as DT1 and, final excel data as DT2
For each row1 in DT1:
2.a. Try assign
DT2.Rows(DT2.Rows.Count-1)(row1.Item(0).ToString) = row1.Item(1).ToString (is adding data if your column exists)
2.b. Catch add data column in DT2 (ColumnName: row1.Item(0).ToString) + the assignment written at 2.a.
Finally use the write range activity to write DT2 within your output excel
Sorry, but I didn’t understand the step 2b so, after assigning values in 2a step I need to use add data column activity in the same for each row and after what I need to do ?
Yes. You need to use add data column activity in order to create your new column (this column from the DT2 is equal with row data content from DT1 - your first column), and
Afterwards, the new column can be filled with data as in 2a step, by using the same assign activity
Hi,
Can you please share a small workflow on this, I used the code that you shared but I am facing error. You can see my flow below,
The first read range will get the values for DT1 and the second read range use the DT2 which will use on the second excel (in that excel only column names presents)
Please see the following file
Pay attention when you are building the DT2 table. It seems that a blank row (with a blank space) needs to be added in order for UiPath to run smoothly
@Debartha_Mitra_DE@Marius_Puscasu
The try-catch block is a great way to handle unexpected situations, for instance, a missing column.
Also, in this scenario, another approach could be to use the Contains check on table’s columns. If DT.Columns.Contains(<columnNameVariable>) →→Add value Else →→Add Data Column (the catch part of your try-catch block)