use of org.apache.poi.ss.usermodel.PatternFormatting in project poi by apache.
the class ConditionalFormats method sameCell.
/**
* Highlight cells based on their values
*/
static void sameCell(Sheet sheet) {
sheet.createRow(0).createCell(0).setCellValue(84);
sheet.createRow(1).createCell(0).setCellValue(74);
sheet.createRow(2).createCell(0).setCellValue(50);
sheet.createRow(3).createCell(0).setCellValue(51);
sheet.createRow(4).createCell(0).setCellValue(49);
sheet.createRow(5).createCell(0).setCellValue(41);
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
// Condition 1: Cell Value Is greater than 70 (Blue Fill)
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.GT, "70");
PatternFormatting fill1 = rule1.createPatternFormatting();
fill1.setFillBackgroundColor(IndexedColors.BLUE.index);
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
// Condition 2: Cell Value Is less than 50 (Green Fill)
ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.LT, "50");
PatternFormatting fill2 = rule2.createPatternFormatting();
fill2.setFillBackgroundColor(IndexedColors.GREEN.index);
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
CellRangeAddress[] regions = { CellRangeAddress.valueOf("A1:A6") };
sheetCF.addConditionalFormatting(regions, rule1, rule2);
sheet.getRow(0).createCell(2).setCellValue("<== Condition 1: Cell Value Is greater than 70 (Blue Fill)");
sheet.getRow(4).createCell(2).setCellValue("<== Condition 2: Cell Value Is less than 50 (Green Fill)");
}
use of org.apache.poi.ss.usermodel.PatternFormatting in project poi by apache.
the class ConditionalFormats method inList.
/**
* Use Excel conditional formatting to highlight items that are in a list on the worksheet.
*/
static void inList(Sheet sheet) {
sheet.createRow(0).createCell(0).setCellValue("Codes");
sheet.createRow(1).createCell(0).setCellValue("AA");
sheet.createRow(2).createCell(0).setCellValue("BB");
sheet.createRow(3).createCell(0).setCellValue("GG");
sheet.createRow(4).createCell(0).setCellValue("AA");
sheet.createRow(5).createCell(0).setCellValue("FF");
sheet.createRow(6).createCell(0).setCellValue("XX");
sheet.createRow(7).createCell(0).setCellValue("CC");
sheet.getRow(0).createCell(2).setCellValue("Valid");
sheet.getRow(1).createCell(2).setCellValue("AA");
sheet.getRow(2).createCell(2).setCellValue("BB");
sheet.getRow(3).createCell(2).setCellValue("CC");
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
// Condition 1: Formula Is =A2=A1 (White Font)
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("COUNTIF($C$2:$C$4,A2)");
PatternFormatting fill1 = rule1.createPatternFormatting();
fill1.setFillBackgroundColor(IndexedColors.LIGHT_BLUE.index);
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
CellRangeAddress[] regions = { CellRangeAddress.valueOf("A2:A8") };
sheetCF.addConditionalFormatting(regions, rule1);
sheet.getRow(2).createCell(3).setCellValue("<== Use Excel conditional formatting to highlight items that are in a list on the worksheet");
}
use of org.apache.poi.ss.usermodel.PatternFormatting in project poi by apache.
the class TestTableStyles method testBuiltinStyleInit.
/**
* Test that a built-in style is initialized properly
*/
@Test
public void testBuiltinStyleInit() {
TableStyle style = XSSFBuiltinTableStyle.TableStyleMedium2.getStyle();
assertNotNull("no style found for Medium2", style);
assertNull("Should not have style info for blankRow", style.getStyle(TableStyleType.blankRow));
DifferentialStyleProvider headerRow = style.getStyle(TableStyleType.headerRow);
assertNotNull("no header row style", headerRow);
FontFormatting font = headerRow.getFontFormatting();
assertNotNull("No header row font formatting", font);
assertTrue("header row not bold", font.isBold());
PatternFormatting fill = headerRow.getPatternFormatting();
assertNotNull("No header fill", fill);
assertEquals("wrong header fill", 4, ((XSSFColor) fill.getFillBackgroundColorColor()).getTheme());
}
Aggregations