How to add text into data tables that shifts themselves automatically?

hi all ,

I have many string variables that store the texts and I want to put them inside the data table in uipath, one by one, right next to each other in the same row and then export to excel. I also want to ensure the first row of the excel file is not overwritten or moved.
How can I make this possible?

Hi @Ben_siu ,

The above task what you want to perform is basically an update operation on the Datatable/Excel, If we have the Datatable already, we could use For Each Row Activity and then update the values using an Assign Activity like below.
image

Then we use Write Range Activity to write the updated datatable back to Excel sheet.

Let us know if this does not work or maybe provide us with Sample Inputs and your Expected output to get a clearer idea on the logic needed.

1 Like

thank you for your reply,

this seems like what I want. but what if I have to add a new column with each text variable?
My workflow is like this:
for each file β†’ for each document β†’ OCR β†’ string β†’ data table β†’ excel
So I dont really know how many columns there will be in each document so I cant specify the name of the columns with each loop. I am thinking if the expected the way to approach this is whenever I have a string variable that I need to put into the data table, I would use the add data column activity. Is there any way you can help with this?

@Ben_siu ,

It would be better if you could provide us with visuals or data in an Excel sheet to better understand the problem at hand.

However, If you are adding the successive string values into different columns, then You could collect all these values that need to be added into separate columns in an array / list. Then we could determine the number of columns that need to be added based on this value.

We could use a For Each Loop to iterate the number of values, if we don’t have a definite column name, we could provide a dummy name with index increasing value.

So we’ll get the columns created then we would just use Add Data row activity with the List/Array value as the value to be added to the datatable.

The above points are described on the way I have assumed the problem at hand, although we might need a better view of the problem as already stated.

Hi,
sorry for the late reply.

workflow: for each file β†’ for each document β†’ OCR β†’ string β†’ data table β†’ excel
This is the excel format I want to achieve ultimately:

for which the strings here are obtained from an already established OCR workflow

@Ben_siu ,

Considering that a workflow is already built and you are able to extract the data needed for the required documents but not able to represent the data properly. In that case, we understand from the above representation that a Folder/File/Document will have multiple string values extracted, for such a case we could maybe adopt the use of Dictionary(Of String,String()). In this way, we collect the multiple string values that is extracted and store it for that particular key i.e file/Folder/Document.

Next, after the extraction process is completed, we’ll have the data in the Dictionary from where we can convert this data into a Datatable easily in the expected format.

Firstly, we would have to get the maximum number of string values present in the Dictionary, that would be our number of Columns to Create for the Output datatable. Next, we use this number and create the number of columns required (dummy column names).

We could then populate this created datatable with the values from the dictionary by either looping through and using Add Data Row Activity or using a Linq.

However, From the Representation of the Output I could not make out what would be the header values. If it is something significant that needs to be in order according to the string values then we would need to shift the approach.