I have 4 excel files in a folder . first 3 are input files and 4th is the output file. I want to loop through all the files in a folder, copy data from sheet1 of all files and append in the 4th file (name: “Output.xlsx”) present in the same folder.
Hi
Welcome to uipath community
Hope these steps could help you resolve this
—use a build datatable activity and create a datatable of same structure that we have in all excel files and get the output of that using a variable named Finaldt of type datatable
— use a assign activity like this Out_filepath = Directory.GetFiles(“yourfolderpath”,”*.xlsx”)
Where Out_filepath is a string array variable
— now use for each loop and pass the above variable as input and change the type argument as string in the property panel of for each loop
— inside the loop use a if condition like Not item.Contains(“Output”)
If that’s true it will go to THEN part where we can use a excel application scope and mention the variable item as file path
— inside the scope use a read range activity and get the output with a variable of type datatable named Outdt
—next to this scope while still being in THEN part use a merge datatable activity and mention the source as Outdt and destination as Finaldt
—or if the above condition fails it will go to ELSE part where we can use a excel application scope and pass the item variable as input and use a read range inside the scope and get the output with a variable of type datatable named Dest_dr ( this will actually cover the output xlsx file)
—now next to this for each loop use a merge datatable activity and mention the source as Finaldt and destination as Dest_dt
— now use a write range workbook activity where mention the filepath of the output.xlsx and mentionrhe datatable as Dest_dt and mention the sheetname where we want to type
Hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @Yousuf_Ali