Wants to Merge the Multiple Excel Files having same headers and different values containing colors in some cells into One Excel File without losing the Color in Output Excel file.
Hey when you read the excel with yellow coloured cells can you check preserver format as True and then see if it stores the coloring info for cells and merge these datatable into one using Merge datatable activity
OR If you already know where its highlighted then you can also use Set Range Color
Hi @Shubham_Arora1
Try following the below steps to achieve the output:
- Use the “Assign” activity to create a new DataTable variable to store the merged data. Let’s call it
mergedDataTable
. Initialize it usingNew DataTable()
. - Use the “Excel Application Scope” activity to read each Excel file one by one. Place the following activities inside this scope:
a. Use the “Read Range” activity to read the data from the Excel file into a DataTable variable, let’s call itcurrentDataTable
.
b. Use a “Merge DataTable” activity to merge thecurrentDataTable
with themergedDataTable
created in step 1. Set the “Destination” property tomergedDataTable
. - After the Excel Application Scope, use another “Excel Application Scope” activity to write the merged DataTable into a new Excel file. Place the following activities inside this scope:
a. Use the “Build Data Table” activity to create a DataTable variable with the same structure as the merged data. Let’s call itoutputDataTable
.
b. Add columns to theoutputDataTable
with the same names and data types as the merged data using the “Add Data Column” activity.
c. Use a “For Each Row” activity to iterate over each row in themergedDataTable
.
d. Inside the “For Each Row” loop, use the “Add Data Row” activity to add each row from themergedDataTable
to theoutputDataTable
.
e. Use the “Write Range” activity to write theoutputDataTable
to a new Excel file. - Save and run the workflow.
Hope it helps!!
Regards,
Please use copy/paste range activity it has a property to copy format as well
https://docs.uipath.com/activities/docs/copy-paste-range-x
Cheers
If you want to do it between excels then use two use excel file activities one inside another and using excel reference as select each in source and destination
Cheers
@Anil_G yeah it’s giving exception
- excel application scope - for destination file
- for each files in folder
- excel application scope files - source file
then copy/ paste range activity
but giving exception sheet doesn’t exists
This si how it looks
BlankProcess - Copy (3).zip (20.1 KB)
please check excel.xaml…it is copying colors as well
you can specify range if you need else it copies everything in the sheet…in destination it is enough to give the start cell
cheers
@Anil_G, i think not possible in Classic as me using Classic Activities, requirement too use classic activities and UiPath activities.
Then you cannot do directly…but first use a copy sheet and copy the sheet to destination workbook then use copy range and copy the range as needed…now after copy as both are in same excel you would not have an issue
cheers
Can you try this-
- Use the Directory.GetFiles activity to retrieve a list of all the Excel files in the specified folder.
- Initialize an empty DataTable that will hold the merged data. Let’s call it
mergedDataTable
. - Iterate through each Excel file using a For Each loop. Set the TypeArgument property to String to represent the file paths.
- Inside the loop, use the Excel Application Scope activity to open each Excel file.
- Within the Excel Application Scope, use the Read Range activity to read the data from each file. Store the output in a DataTable variable, let’s call it
currentDataTable
. - Use the Merge DataTable activity to merge
currentDataTable
withmergedDataTable
. - After merging, use the Excel Application Scope activity again to create a new Excel file.
- Inside the Excel Application Scope, use the Write Range activity to write
mergedDataTable
to the new Excel file. - To preserve the cell colors, you can use the Preserve Format option of the Write Range activity. Set the PreserveFormat property to True.
- Save and close the Excel file.
Thanks!!