Interpret Excel Results
The example below explains how to analyze the results from an .xlsx file and rearrange them in the correct order. It presents activities such as Get Workbook Sheet, Read Cell, Write Cell, Get Cell Color, and Set Range Color. You can find these activities in the UiPath.Excel.Activities package.
This is how the automation process can be built:
-
Open Studio and create a new Process named by default Main.
-
Drag a Sequence container in the Workflow Designer.
- Create the following variables:
Variable Name Variable Type Default Value SheetNameString N/A DT1DataTable N/A CounterInt32 1 CellColorSystem.Drawing.Color N/A -
Drag an Excel Application Scope activity under the Sequence container.
- In the Properties panel add the value
"ExamResults.xlsx"in the WorkbookPath field and select the check boxes for the AutoSave, CreateNewFile and Visible options. These options ensure that the process automatically saves all changes, creates a new file whenever needed, and is visible for all users.
- In the Properties panel add the value
-
Add a Sequence container in the body of the Excel Application Scope activity.
-
Drag a Get Workbook Sheet activity inside the Sequence.
- In the Properties panel add the value
0in the Index field and the variableSheetNamein the Sheet field.
- In the Properties panel add the value
-
Drag an Excel Read Range activity under the Get Workbook Sheet activity.
- In the Properties panel add the variable
SheetNamein the Sheet field and the variableDT1in the DataTable field. - Select the check box for the AddHeaders option for considering the first row of the table a header.
- In the Properties panel add the variable
-
Add a For Each Row activity below the Read Range activity.
- Insert the variable
DT1in the DataTable field.
- Insert the variable
-
Place a Sequence container inside the body of the For Each Row activity.
- Create the following variables:
Variable Name Variable Type Default Value CellValueString N\A GradeDouble N\A -
Drag an Assign activity in the body of the newly created Sequence.
- Add the variable
Counterin the To field and the valueCounter + 1in the Value field.
- Add the variable
-
Drag a Get Cell Color activity below the Assign activity.
- In the Properties panel add the value
"D" + Counter.ToStringin the Cell field, the variableSheetNamein the SheetName field and the variableCellColorin the Color field.
- In the Properties panel add the value
-
Add an Excel Read Cell activity below the Get Cell Color activity. This activity reads the results from the
.xlsxfile.- In the Properties panel, add the value
"D" + Counter.ToStringin the Cell field, the variableSheetNamein the SheetName field and the variableCellValuein the Result field.
- In the Properties panel, add the value
-
Add another Excel Read Cell activity below the first one. This activity reads the grades from the
.xlsxfile.- In the Properties panel, add the value
"C" + Counter.ToStringin the Cell field, the variableSheetNamein the SheetName field and the variableGradein the Result field.
- In the Properties panel, add the value
-
Place an If activity underneath the last Read Cell activity.
- Populate the Condition field with this value
Grade >= 5.
- Populate the Condition field with this value
-
Add two Sequence containers, one for the Then field and another one for the Else field. These activities set different colors for each result.
-
In the body of the Then Sequence add a Set Range Color activity. This writes the result Passed in blue.
- In the Properties panel add the value
System.Drawing.Color.Bluein the Color field, the value"D" + Counter.ToStringin the Range field and the variableSheetNamein the SheetName field.
- In the Properties panel add the value
-
Drag a Write Cell activity below the Set Range Color activity.
- In the Properties panel add the value
"D" + Counter.ToStringin the Range field, the variableSheetNamein the SheetName field and the value"Passed"in the Value field.
- In the Properties panel add the value
-
In the body of the Else Sequence add a Set Range Color activity. This writes the result Failed in red.
- In the Properties panel add the value
System.Drawing.Color.Redin the Color field, the value"D" + Counter.ToStringin the Range field and the variableSheetNamein the SheetName field.
- In the Properties panel add the value
-
Drag a Write Cell activity below the Set Range Color activity.
- In the Properties panel add the value
"D" + Counter.ToStringin the Range field, the variableSheetNamein the SheetName field and the value"Failed"in the Value field.
- In the Properties panel add the value
-
Place a Sequence container below the If activity.
-
Drag an Excel Write Cell activity in the body of the sequence.
- In the Properties panel add the value
"E" + Counter.ToStringin the Range field, the variableSheetNamein the SheetName field and theCellValuein the Value field.
- In the Properties panel add the value
-
Add a Set Range Color below the Write Cell activity.
- In the Properties panel add the variable
CellColorin the Color field, the value"E" + Counter.ToStringin the Range field and the variableSheetNamein the SheetName field.
- In the Properties panel add the variable
-
Run the process. The automation process filters the data and creates a new file with the sorted results.