Apply Conditional Formatting in Worksheets

Using Aspose.Cells to Apply Conditional Formatting Based on Cell Value

  1. Download and Install Aspose.Cells.
    1. Download Aspose.Cells for Python via .NET.
  2. Install it on your development computer. All Aspose components, when installed, work in evaluation mode. The evaluation mode has no time limit and it only injects watermarks into produced documents.
  3. Create a project. Start Visual Studio.NET and create a new console application. This example creates a Python console application, but you can use VB.NET too.
  4. Add references. Add a reference to Aspose.Cells to your project.
  5. *Apply conditional formatting based on cell value. Below is the code used to accomplish the task. I applies conditional formatting on a cell.

When the above code is executed, conditional formatting is applied to cell “A1” in first worksheet of the output file (output.xls). The conditional formatting applied to A1 depends on the cell value. If the cell value of A1 is between 50 and 100 the background color is red due to the conditional formatting applied.

Using Aspose.Cells to Apply Conditional Formatting Based on Formula

  1. Applying conditional formatting depending on formula (Code Snippet) Below is the code to accomplish the task. It applies conditional formatting on B3.

When the above code is executed, conditional formatting is applied to cell “B3” in the first worksheet of the output file (output.xls). The conditional formatting applied depends on the formula which calculates the value of “B3” as sum of B1 & B2.