1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================== */
18 package org
.apache
.poi
.hssf
.usermodel
;
20 import junit
.framework
.TestCase
;
22 import org
.apache
.poi
.hssf
.record
.CFRuleRecord
.ComparisonOperator
;
23 import org
.apache
.poi
.hssf
.util
.HSSFColor
;
24 import org
.apache
.poi
.hssf
.util
.Region
;
27 * @author Dmitriy Kumshayev
29 public final class TestHSSFConditionalFormatting
extends TestCase
31 public void testCreateCF()
33 HSSFWorkbook workbook
= new HSSFWorkbook();
34 HSSFSheet sheet
= workbook
.createSheet();
37 HSSFFontFormatting fontFmt
= new HSSFFontFormatting();
38 fontFmt
.setFontStyle(true, false);
40 HSSFBorderFormatting bordFmt
= new HSSFBorderFormatting();
41 bordFmt
.setBorderBottom(HSSFBorderFormatting
.BORDER_THIN
);
42 bordFmt
.setBorderTop(HSSFBorderFormatting
.BORDER_THICK
);
43 bordFmt
.setBorderLeft(HSSFBorderFormatting
.BORDER_DASHED
);
44 bordFmt
.setBorderRight(HSSFBorderFormatting
.BORDER_DOTTED
);
46 HSSFPatternFormatting patternFmt
= new HSSFPatternFormatting();
47 patternFmt
.setFillBackgroundColor(HSSFColor
.RED
.index
);
49 HSSFConditionalFormattingRule
[] cfRules
=
51 sheet
.createConditionalFormattingRule(formula
, fontFmt
, bordFmt
, patternFmt
),
52 sheet
.createConditionalFormattingRule(ComparisonOperator
.BETWEEN
, "1", "2", fontFmt
, bordFmt
, patternFmt
)
58 new Region(0,col
,65535,col
)
61 sheet
.addConditionalFormatting(regions
, cfRules
);
62 sheet
.addConditionalFormatting(regions
, cfRules
);
65 assertEquals(2, sheet
.getNumConditionalFormattings());
66 sheet
.removeConditionalFormatting(1);
67 assertEquals(1, sheet
.getNumConditionalFormattings());
68 HSSFConditionalFormatting cf
= sheet
.getConditionalFormattingAt(0);
71 regions
= cf
.getFormattingRegions();
72 assertNotNull(regions
);
73 assertEquals(1, regions
.length
);
74 Region r
= regions
[0];
75 assertEquals(1, r
.getColumnFrom());
76 assertEquals(1, r
.getColumnTo());
77 assertEquals(0, r
.getRowFrom());
78 assertEquals(65535, r
.getRowTo());
80 assertEquals(2, cf
.getNumberOfRules());
82 HSSFConditionalFormattingRule rule1
= cf
.getRule(0);
83 assertEquals("7",rule1
.getFormula1());
84 assertNull(rule1
.getFormula2());
86 HSSFFontFormatting r1fp
= rule1
.getFontFormatting();
89 assertTrue(r1fp
.isItalic());
90 assertFalse(r1fp
.isBold());
92 HSSFBorderFormatting r1bf
= rule1
.getBorderFormatting();
94 assertEquals(HSSFBorderFormatting
.BORDER_THIN
, r1bf
.getBorderBottom());
95 assertEquals(HSSFBorderFormatting
.BORDER_THICK
,r1bf
.getBorderTop());
96 assertEquals(HSSFBorderFormatting
.BORDER_DASHED
,r1bf
.getBorderLeft());
97 assertEquals(HSSFBorderFormatting
.BORDER_DOTTED
,r1bf
.getBorderRight());
99 HSSFPatternFormatting r1pf
= rule1
.getPatternFormatting();
101 assertEquals(HSSFColor
.RED
.index
,r1pf
.getFillBackgroundColor());
103 HSSFConditionalFormattingRule rule2
= cf
.getRule(1);
104 assertEquals("2",rule2
.getFormula2());
105 assertEquals("1",rule2
.getFormula1());