Looping through all excel files in a folder

Hi,

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.

can anyone help here

Hi, @Yousuf_Ali! I think this Go! component has what you need: https://go.uipath.com/component/merge-content-of-multiple-excel-files

1 Like

Hi @Yousuf_Ali

Use directory.getfiles(inputffilepath)

For each item in filename
If (item.tostring.contains("inputfilename)

1 Like

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

1 Like

¡Hi @Yousuf_Ali, welcome to UiPath Community!

Here it’s the solution for your problem, bless!

Main.xaml (7.6 KB)

1 Like

Hy @Yousuf_Ali

Welcome to Forum, Refer the following program
Main.xaml (8.5 KB)
Abc.7z (11.8 KB)

You can find the result file in Result.xlsx

All the Best.

1 Like

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