I’m generating an XSSF spreadsheet in Java using Apache POI. What I’m trying to do is generate a conditional formatting formula that’s similar to “if the value in cell $A2=”X”, turn $C2 green”, and then apply it all the way down column C.

I haven’t seen any examples of this online, though—all examples I seen only deal with one column at a time, not references. Is it possible to do?

The conditional formatting rule you want to apply is something like:

```
SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule cfr1 = scf.createConditionalFormattingRule("(indirect(address(row(), column() - 1))) = \"CDS correct\"");
```

The formula finds whatever the value is of the cell two to the left of the current cell. You can then use the CellRangeAddress appropriate for the number of rows in the C column you have populated.

### Answer：

What you need is to put them in ( ) to allow that.

Try this, in CondiFormat to cell C2 use a formula to determine which cells to format and type in this formula `=($F2="CDS correct")`

That will be True when your F column has “CDS correct”

Hope this helps,

-Scheballs

Tags: apache, excelexcel