how to get the cell color in Excel using uipath
To get the cell color in Excel using UiPath, you can use the following steps
step-1:
Drag and drop an Excel Application Scope activity onto your workflow.
step-2:
In the Properties panel of the Excel Application Scope activity, configure the following properties:
- WorkbookPath: Enter the file path of the Excel workbook you want to work with. For example, “C:\Path\to\your\file.xlsx”.
- Password: If your Excel file is password-protected, provide the password required to open the file.
Step-3:
Drag and Drop Set Range Color Activity from activities panel to the designer panel as shown below:
Now, let us look at the properties for this activity which inside the excel application scope:
- Color- We need to mention the color that is filled in that particular cell or a range.
The input color that we are using in this example is green and we need to mention that like this System.Drawing.Color.Green.
- Range- In this property, if you want to set the color for a certain range pass the input like this A1:A10 else pass it as shown in the image.
- SheetName- The name of the sheet where you want all this to happen.
- With this we successfully colored the cell A2 as shown below:
step-4:
3. Inside the Excel Application Scope activity, you can add other activities to perform actions on the Excel file. Here’s a step-by-step guide to getting the cell color:
c. Get Cell Color:
- Drag and drop the Get Cell Color activity inside the Excel Application Scope.
- Configure the following properties:
- SheetName: Enter the sheet name containing the cell you want to check.
- Cell: Specify the cell whose color you want to retrieve. You can use the row index and column index to access the cell. For example, if you want to check the color of cell A1, you can use “A” + (row. Index + 2).ToString(). The “+2” accounts for the zero-based index of the DataTable rows.
- OutputColor: Create a variable of type System.Drawing.Color to store the color of the cell.
- You can now access the cell value and cell color stored in the respective variables and perform actions based on them.
step-5:
This is the output of above steps:
.