Lines 20-34
package org.apache.poi.hssf.usermodel;
Link Here
|
20 |
|
20 |
|
21 |
import static org.junit.Assert.*; |
21 |
import static org.junit.Assert.*; |
22 |
import java.io.FileNotFoundException; |
22 |
import java.io.FileNotFoundException; |
|
|
23 |
import java.io.FileOutputStream; |
23 |
import java.io.IOException; |
24 |
import java.io.IOException; |
24 |
|
25 |
|
25 |
import org.apache.poi.hssf.HSSFITestDataProvider; |
26 |
import org.apache.poi.hssf.HSSFITestDataProvider; |
26 |
import org.apache.poi.hssf.util.HSSFColor; |
27 |
import org.apache.poi.hssf.util.HSSFColor; |
27 |
import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting; |
28 |
import org.apache.poi.ss.usermodel.*; |
28 |
import org.apache.poi.ss.usermodel.Color; |
29 |
import org.apache.poi.ss.util.CellRangeAddress; |
29 |
import org.apache.poi.ss.usermodel.Sheet; |
|
|
30 |
import org.apache.poi.ss.usermodel.SheetConditionalFormatting; |
31 |
import org.apache.poi.ss.usermodel.Workbook; |
32 |
import org.junit.Test; |
30 |
import org.junit.Test; |
33 |
|
31 |
|
34 |
/** |
32 |
/** |
Lines 122-125
public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm
Link Here
|
122 |
assertNotNull(wbBack); |
120 |
assertNotNull(wbBack); |
123 |
wbBack.close(); |
121 |
wbBack.close(); |
124 |
} |
122 |
} |
|
|
123 |
|
124 |
|
125 |
@Test |
126 |
public void test52122() throws Exception { |
127 |
Workbook workbook = new HSSFWorkbook(); |
128 |
Sheet sheet = workbook.createSheet("Conditional Formatting Test"); |
129 |
sheet.setColumnWidth(0, 256 * 10); |
130 |
sheet.setColumnWidth(1, 256 * 10); |
131 |
sheet.setColumnWidth(2, 256 * 10); |
132 |
|
133 |
// Create some content. |
134 |
// row 0 |
135 |
Row row = sheet.createRow(0); |
136 |
|
137 |
Cell cell0 = row.createCell(0); |
138 |
cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
139 |
cell0.setCellValue(100); |
140 |
|
141 |
Cell cell1 = row.createCell(1); |
142 |
cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
143 |
cell1.setCellValue(120); |
144 |
|
145 |
Cell cell2 = row.createCell(2); |
146 |
cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
147 |
cell2.setCellValue(130); |
148 |
|
149 |
// row 1 |
150 |
row = sheet.createRow(1); |
151 |
|
152 |
cell0 = row.createCell(0); |
153 |
cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
154 |
cell0.setCellValue(200); |
155 |
|
156 |
cell1 = row.createCell(1); |
157 |
cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
158 |
cell1.setCellValue(220); |
159 |
|
160 |
cell2 = row.createCell(2); |
161 |
cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
162 |
cell2.setCellValue(230); |
163 |
|
164 |
// row 2 |
165 |
row = sheet.createRow(2); |
166 |
|
167 |
cell0 = row.createCell(0); |
168 |
cell0.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
169 |
cell0.setCellValue(300); |
170 |
|
171 |
cell1 = row.createCell(1); |
172 |
cell1.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
173 |
cell1.setCellValue(320); |
174 |
|
175 |
cell2 = row.createCell(2); |
176 |
cell2.setCellType(org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC); |
177 |
cell2.setCellValue(330); |
178 |
|
179 |
// Create conditional formatting, CELL1 should be yellow if CELL0 is not blank. |
180 |
SheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting(); |
181 |
|
182 |
ConditionalFormattingRule rule = formatting.createConditionalFormattingRule("$A$1>75"); |
183 |
|
184 |
PatternFormatting pattern = rule.createPatternFormatting(); |
185 |
pattern.setFillBackgroundColor(IndexedColors.BLUE.index); |
186 |
pattern.setFillPattern(PatternFormatting.SOLID_FOREGROUND); |
187 |
|
188 |
CellRangeAddress[] range = {CellRangeAddress.valueOf("B2:C2")}; |
189 |
CellRangeAddress[] range2 = {CellRangeAddress.valueOf("B1:C1")}; |
190 |
|
191 |
formatting.addConditionalFormatting(range, rule); |
192 |
formatting.addConditionalFormatting(range2, rule); |
193 |
|
194 |
// Write file. |
195 |
FileOutputStream fos = new FileOutputStream("/tmp/52122_conditional-sheet.xls"); |
196 |
try { |
197 |
workbook.write(fos); |
198 |
} finally { |
199 |
fos.close(); |
200 |
} |
201 |
} |
125 |
} |
202 |
} |
126 |
- |
|
|