Hello, I am rather new to RPA and need some help. I have a folder that hold multiple xl sheets, i want to copy data from each file and paste into 1 file. Each file holds the same headers.
I’m not giving you directly the code as you are still in learning phase and you should be coding yourself. It’s pretty much simple use case. Here are the Solution Design level steps.
- Read the Files: Use the “Directory.GetFiles” activity to get a list of all Excel files in your folder.
- Loop Through Files: Use a “For Each” loop to iterate through each file.
- Open Excel File: Inside the loop, use the “Excel Application Scope” activity to open each Excel file.
- Read Data: Use the “Read Range” activity to read the data from each Excel file.
- Write Data: Use the “Write Range” activity to write the data into a single Excel file.
Here’s a more detailed breakdown:
1. Read Files
Use the Directory.GetFiles
method to get a list of Excel files in your folder. Store this list in an array variable.
2. Loop Through Files
Use a “For Each” loop activity to iterate through each file in the array variable.
3. Open Excel File
Inside the loop, use the “Excel Application Scope” activity to open each Excel file.
4. Read Data
Within the “Excel Application Scope”, use the “Read Range” activity to read the data from each Excel file. Store this data in a DataTable variable.
5. Write Data
After reading data from each file, use another “Excel Application Scope” activity to open the output Excel file where you want to consolidate the data.
Inside this scope, use the “Write Range” activity to write the data from each DataTable into the output Excel file. Make sure to write the data below the previously written data to avoid overwriting. Use Append Range
activity for second file onward.
LLM helped me to write this answer
Thanks,
Ashok
Create sourceDT and finalDT variables as System.Data.Datatable
- For Each File in Folder
** Use Excel/Read Range into sourceDT
** Merge Data Table sourceDT into finalDT - //end For Each
Now you have all the data in finalDT and can Write Range it to a new file.
- For each file in folder to loop through all excels
- Inside loop read range workbook and give path as currentfile.FullName
- Use merge datatable and merge the read data to finaldt
- Write the finaldt to a output file as needed
Cheers
1 ) Put all file in one folder
2 ) Read all the file
3 ) Add all files in one data table / or database
4) Write the data table to the files
Note: if file size is huge then use the data base and get good amount of RAM.
Hello,
Thank you for your help so far, what you are saying makes complete sense but for some reason its not working and i don’t know what i’m doing wrong.
Thanks
Vicky
Main.xaml (17.5 KB)
Your workflow looks perfect…Can you please check folder path and files are in folder and debug the process
Regards,
When i click run it opens up GR PLAN file and only 1 of the files in the folder and does noting else.