Line 0
Link Here
|
|
|
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 |
8 |
|
9 |
http://www.apache.org/licenses/LICENSE-2.0 |
10 |
|
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 |
==================================================================== */ |
17 |
package org.apache.poi.hssf.usermodel; |
18 |
|
19 |
import junit.framework.TestCase; |
20 |
|
21 |
import org.apache.poi.hssf.util.HSSFColor; |
22 |
import org.apache.poi.hssf.util.Region; |
23 |
|
24 |
public class TestHSSFConfditionalFormatting extends TestCase |
25 |
{ |
26 |
public void testLastAndFirstColumns() |
27 |
{ |
28 |
HSSFWorkbook workbook = new HSSFWorkbook(); |
29 |
HSSFSheet sheet = workbook.createSheet(); |
30 |
String formula = "7"; |
31 |
|
32 |
HSSFFontFormatting fontFmt = new HSSFFontFormatting(); |
33 |
fontFmt.setFontStyle(true, false); |
34 |
|
35 |
HSSFBorderFormatting bordFmt = new HSSFBorderFormatting(); |
36 |
bordFmt.setBorderBottom(HSSFBorderFormatting.BORDER_THIN); |
37 |
bordFmt.setBorderTop(HSSFBorderFormatting.BORDER_THICK); |
38 |
bordFmt.setBorderLeft(HSSFBorderFormatting.BORDER_DASHED); |
39 |
bordFmt.setBorderRight(HSSFBorderFormatting.BORDER_DOTTED); |
40 |
|
41 |
HSSFPatternFormatting patternFmt = new HSSFPatternFormatting(); |
42 |
patternFmt.setFillBackgroundColor(HSSFColor.RED.index); |
43 |
|
44 |
HSSFConditionalFormattingRule [] cfRules = new HSSFConditionalFormattingRule[] |
45 |
{ |
46 |
sheet.createConditionalFormattingRule(formula, fontFmt, bordFmt, patternFmt), |
47 |
sheet.createConditionalFormattingRule(HSSFConditionalFormattingRule.COMPARISON_OPERATOR_BETWEEN, "1", "2", fontFmt, bordFmt, patternFmt) |
48 |
}; |
49 |
|
50 |
short col = 1; |
51 |
Region [] regions = new Region[] |
52 |
{ |
53 |
new Region(1,col,-1,col) |
54 |
}; |
55 |
|
56 |
sheet.addConditionalFormatting(regions, cfRules); |
57 |
sheet.addConditionalFormatting(regions, cfRules); |
58 |
|
59 |
// Verification |
60 |
assertEquals(2, sheet.getNumConditionalFormattings()); |
61 |
sheet.removeConditionalFormatting(1); |
62 |
assertEquals(1, sheet.getNumConditionalFormattings()); |
63 |
HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(0); |
64 |
assertNotNull(cf); |
65 |
|
66 |
regions = cf.getFormattingRegions(); |
67 |
assertNotNull(regions); |
68 |
assertEquals(1, regions.length); |
69 |
Region r = regions[0]; |
70 |
assertEquals((short)1, r.getColumnFrom()); |
71 |
assertEquals((short)1, r.getColumnTo()); |
72 |
assertEquals(1, r.getRowFrom()); |
73 |
assertEquals(-1, r.getRowTo()); |
74 |
|
75 |
assertEquals(2, cf.getNumbOfRules()); |
76 |
|
77 |
HSSFConditionalFormattingRule rule1 = cf.getRule(0); |
78 |
assertEquals("7",rule1.getFormula1()); |
79 |
assertNull(rule1.getFormula2()); |
80 |
|
81 |
HSSFConditionalFormattingRule rule2 = cf.getRule(1); |
82 |
assertEquals("2",rule2.getFormula2()); |
83 |
assertEquals("1",rule2.getFormula1()); |
84 |
|
85 |
} |
86 |
|
87 |
} |