문제

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!

도움이 되었습니까?

해결책 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?

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top