if (cfRules.length > 3) {\r
throw new IllegalArgumentException("Number of rules must not exceed 3");\r
}\r
- XSSFConditionalFormattingRule[] hfRules;\r
- if(cfRules instanceof XSSFConditionalFormattingRule[]) hfRules = (XSSFConditionalFormattingRule[])cfRules;\r
- else {\r
- hfRules = new XSSFConditionalFormattingRule[cfRules.length];\r
- System.arraycopy(cfRules, 0, hfRules, 0, hfRules.length);\r
- }\r
+\r
CellRangeAddress[] mergeCellRanges = CellRangeUtil.mergeCellRanges(regions);\r
CTConditionalFormatting cf = _sheet.getCTWorksheet().addNewConditionalFormatting();\r
List<String> refs = new ArrayList<String>();\r
for(CellRangeAddress a : mergeCellRanges) refs.add(a.formatAsString());\r
cf.setSqref(refs);\r
\r
-\r
int priority = 1;\r
for(CTConditionalFormatting c : _sheet.getCTWorksheet().getConditionalFormattingArray()){\r
priority += c.sizeOfCfRuleArray();\r
XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet);
-
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
- int cfCount = ctWorksheet.sizeOfConditionalFormattingArray();
- for(int j = 0; j< cfCount; j++){
- CTConditionalFormatting cf = ctWorksheet.getConditionalFormattingArray(j);
+ CTConditionalFormatting[] conditionalFormattingArray = ctWorksheet.getConditionalFormattingArray();
+ // iterate backwards due to possible calls to ctWorksheet.removeConditionalFormatting(j)
+ for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
+ CTConditionalFormatting cf = conditionalFormattingArray[j];
ArrayList<CellRangeAddress> cellRanges = new ArrayList<CellRangeAddress>();
for (Object stRef : cf.getSqref()) {
}
for(CTCfRule cfRule : cf.getCfRuleArray()){
- int formulaCount = cfRule.sizeOfFormulaArray();
- for (int i = 0; i < formulaCount; i++) {
- String formula = cfRule.getFormulaArray(i);
+ String[] formulaArray = cfRule.getFormulaArray();
+ for (int i = 0; i < formulaArray.length; i++) {
+ String formula = formulaArray[i];
Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex);
if (shifter.adjustFormula(ptgs, sheetIndex)) {
String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
}\r
\r
public void testShiftRows() {\r
-\r
Workbook wb = _testDataProvider.createWorkbook();\r
Sheet sheet = wb.createSheet();\r
\r
\r
PatternFormatting patternFmt = rule1.createPatternFormatting();\r
patternFmt.setFillBackgroundColor(IndexedColors.YELLOW.index);\r
- ConditionalFormattingRule [] cfRules = { rule1, };\r
+\r
+ ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(\r
+ ComparisonOperator.BETWEEN, "SUM(A10:A15)", "1+SUM(B16:B30)");\r
+ BorderFormatting borderFmt = rule2.createBorderFormatting();\r
+ borderFmt.setBorderDiagonal((short) 2);\r
\r
CellRangeAddress [] regions = {\r
new CellRangeAddress(2, 4, 0, 0), // A3:A5\r
};\r
- sheetCF.addConditionalFormatting(regions, cfRules);\r
+ sheetCF.addConditionalFormatting(regions, rule1);\r
+ sheetCF.addConditionalFormatting(regions, rule2);\r
\r
// This row-shift should destroy the CF region\r
sheet.shiftRows(10, 20, -9);\r
assertEquals(0, sheetCF.getNumConditionalFormattings());\r
\r
// re-add the CF\r
- sheetCF.addConditionalFormatting(regions, cfRules);\r
+ sheetCF.addConditionalFormatting(regions, rule1);\r
+ sheetCF.addConditionalFormatting(regions, rule2);\r
\r
// This row shift should only affect the formulas\r
sheet.shiftRows(14, 17, 8);\r
- ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);\r
- assertEquals("SUM(A10:A23)", cf.getRule(0).getFormula1());\r
- assertEquals("1+SUM(B24:B30)", cf.getRule(0).getFormula2());\r
+ ConditionalFormatting cf1 = sheetCF.getConditionalFormattingAt(0);\r
+ assertEquals("SUM(A10:A23)", cf1.getRule(0).getFormula1());\r
+ assertEquals("1+SUM(B24:B30)", cf1.getRule(0).getFormula2());\r
+ ConditionalFormatting cf2 = sheetCF.getConditionalFormattingAt(1);\r
+ assertEquals("SUM(A10:A23)", cf2.getRule(0).getFormula1());\r
+ assertEquals("1+SUM(B24:B30)", cf2.getRule(0).getFormula2());\r
\r
sheet.shiftRows(0, 8, 21);\r
- cf = sheetCF.getConditionalFormattingAt(0);\r
- assertEquals("SUM(A10:A21)", cf.getRule(0).getFormula1());\r
- assertEquals("1+SUM(#REF!)", cf.getRule(0).getFormula2());\r
+ cf1 = sheetCF.getConditionalFormattingAt(0);\r
+ assertEquals("SUM(A10:A21)", cf1.getRule(0).getFormula1());\r
+ assertEquals("1+SUM(#REF!)", cf1.getRule(0).getFormula2());\r
+ cf2 = sheetCF.getConditionalFormattingAt(1);\r
+ assertEquals("SUM(A10:A21)", cf2.getRule(0).getFormula1());\r
+ assertEquals("1+SUM(#REF!)", cf2.getRule(0).getFormula2());\r
}\r
\r
protected void testRead(String filename){\r