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 Node.js via C++.
  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 your Node.js project by initializing it. This example creates a Node.js console application.
  4. Add references. Add a reference to Aspose.Cells to your project, for example by requiring the package as follows:
    const AsposeCells = require("aspose.cells.node");
    
  5. Apply conditional formatting based on cell value. Below is the code used to accomplish the task. It applies conditional formatting on a cell.

When the above code is executed, conditional formatting is applied to cell “A1” in the 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 the sum of B1 & B2.