Question

I'm having trouble with reading the conditional formatting in an Excel Sheet using Apache POI 3.9. The Excel file was created using MS Excel 2010, some conditional formatting was added (I unzipped the .xlsx file, checked the sheet1.xml and it has several x14:conditionalFormatting tags) but sheet.getSheetConditionalFormatting().getNumConditionalFormattings() always returns 0. I can read other properties, including merged cells, without problems. Am I missing something?

Thanks!

Was it helpful?

Solution 2

I think I see the problem. POI does support Conditional Formatting and it reads them correctly only when the value is not a reference to another cell. So for example if I use the rule Format only cells that contain and select Specific Text and containing and a reference to a cell (=$A$1) then it won't be read by POI. If I change the reference to a static value ('test POI') then it will be handled correctly.

Is there a way to force POI to handle references correctly?

OTHER TIPS

SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();

        ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "481", "499");
        PatternFormatting fill1 = rule1.createPatternFormatting();
        fill1.setFillBackgroundColor(IndexedColors.LIGHT_TURQUOISE.index);
        fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

CellRangeAddress[] regions = { CellRangeAddress.valueOf("N1:N" + rownum) };

        sheetCF.addConditionalFormatting(regions, cfRules);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top