You'll need two rules, one for red and one for blue. Subtract 1 from ROW()
so that row 11 becomes 10 and row 15 becomes 14, so that the result of the mod is less than 5. Also, row 10 becomes 9 and the mod is greater than or equal to 5, so it will become blue. The pattern repeats after 10 rows, so that's why the mod operand is 10
.
ConditionalFormattingRule red = sheetCF.createConditionalFormattingRule(
"MOD(ROW() - 1, 10) < 5");
FontFormatting ffRed = red.createFontFormatting();
ffRed.setFontColorIndex(IndexedColors.RED.index);
ConditionalFormattingRule blue = sheetCF.createConditionalFormattingRule(
"MOD(ROW() - 1, 10) >= 5");
FontFormatting ffBlue = blue.createFontFormatting();
ffBlue.setFontColorIndex(IndexedColors.BLUE.index);
Then you can add the conditional formatting to your sheet with your SheetConditionalFormatting
object, with an appropriate CellRangeAddress
.
For more detail, see the Quick Guide on Conditional Formatting.