我工作的Apache poi API,我想有条件地着色的线条,规则是交替的颜色后5线:线1-5红,行6-10蓝色,行11-15红。等等。
这一规则:
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("MOD(ROW(),2)");以不同的颜色替换行。
我怎么能写我的规则??
发布于 2014-03-21 16:18:55
你需要两条规则,一条是红色的,一条是蓝色的。从ROW()中减去1,使第11行变为10,第15行变为14,这样mod的结果小于5。此外,第10行变为9,mod大于或等于5,因此它将变成蓝色。模式在10行后重复,这就是mod操作数为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);然后,可以使用适当的SheetConditionalFormatting对象将条件格式添加到工作表中。
有关更多细节,请参见条件格式快速指南。
发布于 2014-03-21 16:00:30
在我看来,以下内容(或者类似的东西,可能是(ROW()+1)或(ROW()-1)而不是ROW())应该能起作用:
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("MOD(ROW() / 5,2)");https://stackoverflow.com/questions/22563444
复制相似问题