Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648417 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r648156 | yegor | 2008-04-15 08:54:20 +0100 (Tue, 15 Apr 2008) | 1 line
TextShape is a common superclass of all shapes that can hold text. The subclasses are TextBox and AutoShape.
........
r648203 | yegor | 2008-04-15 11:05:22 +0100 (Tue, 15 Apr 2008) | 1 line
start improving handling of resources in HSLF. PPFont object represents a font in a presenatation.
........
r648274 | yegor | 2008-04-15 16:11:13 +0100 (Tue, 15 Apr 2008) | 1 line
TextSpecInfoAtom is present in PPT 2003+. When the text is changed we must update this record, otherwise the ppt becomes corrupted
........
r648276 | yegor | 2008-04-15 16:12:58 +0100 (Tue, 15 Apr 2008) | 1 line
Improved factoring of ppt objects. For ppt tabels Slide.getShapes() returns the Table object (was ShapeGroup)
........
r648303 | nick | 2008-04-15 17:00:50 +0100 (Tue, 15 Apr 2008) | 1 line
Nice and small change here... Update the formula parser code to use usermodel.HSSFWorkbook instead of model.Workbook. This should keep things a bit cleaner, and make it much easier for the formula code to work with XSSF
........
r648334 | josh | 2008-04-15 18:07:06 +0100 (Tue, 15 Apr 2008) | 1 line
Conditional Formatting (30311) - API improvements, added HSSFSheetConditionalFormatting
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@648444 13f79535-47bb-0310-9956-ffa450edef68
2008-04-15 18:47:30 -04:00
|
|
|
/* ====================================================================
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.model.Sheet;
|
|
|
|
import org.apache.poi.hssf.record.CFRuleRecord;
|
|
|
|
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
|
|
|
|
import org.apache.poi.ss.util.Region;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>
|
|
|
|
*
|
|
|
|
* @author Dmitriy Kumshayev
|
|
|
|
*/
|
|
|
|
public final class HSSFSheetConditionalFormatting {
|
|
|
|
|
|
|
|
private final HSSFWorkbook _workbook;
|
|
|
|
private final Sheet _sheet;
|
|
|
|
|
|
|
|
/* package */ HSSFSheetConditionalFormatting(HSSFWorkbook workbook, Sheet sheet) {
|
|
|
|
_workbook = workbook;
|
|
|
|
_sheet = sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A factory method allowing to create a conditional formatting rule
|
Merged revisions 668156-671000 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r668257 | yegor | 2008-06-16 19:38:59 +0100 (Mon, 16 Jun 2008) | 1 line
TextShape.getMarginLeft() returned incorrect value. Added a unit test for text margins.
........
r668259 | yegor | 2008-06-16 19:40:51 +0100 (Mon, 16 Jun 2008) | 1 line
patch from bug #45177: Remove GPL reference in NOTICE
........
r669140 | nick | 2008-06-18 12:35:04 +0100 (Wed, 18 Jun 2008) | 1 line
A partial fix for bug #30978, but something still remains, which seems to be related to changing the ptg
........
r669456 | nick | 2008-06-19 12:47:48 +0100 (Thu, 19 Jun 2008) | 1 line
Improved HWPF Range.replaceText, from N. Hira in bug #45001
........
r669658 | josh | 2008-06-19 20:07:20 +0100 (Thu, 19 Jun 2008) | 1 line
Fix for bug 45234 - Removed incorrect shared formula conversion in CFRuleRecord
........
r669809 | josh | 2008-06-20 08:10:03 +0100 (Fri, 20 Jun 2008) | 1 line
Fix for bug 30978 - small re-arrangement of class Ptg hierarchy for DeletedRef3DPtg and DeletedArea3DPtg. Similar to c664220
........
r670190 | yegor | 2008-06-21 13:41:34 +0100 (Sat, 21 Jun 2008) | 1 line
started a new section for poi-3.2 family, updated release date of 3.2-FINAL
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674287 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 08:11:37 -04:00
|
|
|
* with a cell comparison operator<p/>
|
|
|
|
* TODO - formulas containing cell references are currently not parsed properly
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648417 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r648156 | yegor | 2008-04-15 08:54:20 +0100 (Tue, 15 Apr 2008) | 1 line
TextShape is a common superclass of all shapes that can hold text. The subclasses are TextBox and AutoShape.
........
r648203 | yegor | 2008-04-15 11:05:22 +0100 (Tue, 15 Apr 2008) | 1 line
start improving handling of resources in HSLF. PPFont object represents a font in a presenatation.
........
r648274 | yegor | 2008-04-15 16:11:13 +0100 (Tue, 15 Apr 2008) | 1 line
TextSpecInfoAtom is present in PPT 2003+. When the text is changed we must update this record, otherwise the ppt becomes corrupted
........
r648276 | yegor | 2008-04-15 16:12:58 +0100 (Tue, 15 Apr 2008) | 1 line
Improved factoring of ppt objects. For ppt tabels Slide.getShapes() returns the Table object (was ShapeGroup)
........
r648303 | nick | 2008-04-15 17:00:50 +0100 (Tue, 15 Apr 2008) | 1 line
Nice and small change here... Update the formula parser code to use usermodel.HSSFWorkbook instead of model.Workbook. This should keep things a bit cleaner, and make it much easier for the formula code to work with XSSF
........
r648334 | josh | 2008-04-15 18:07:06 +0100 (Tue, 15 Apr 2008) | 1 line
Conditional Formatting (30311) - API improvements, added HSSFSheetConditionalFormatting
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@648444 13f79535-47bb-0310-9956-ffa450edef68
2008-04-15 18:47:30 -04:00
|
|
|
*
|
|
|
|
* @param comparisonOperation - a constant value from
|
|
|
|
* <tt>{@link HSSFConditionalFormattingRule.ComparisonOperator}</tt>: <p>
|
|
|
|
* <ul>
|
|
|
|
* <li>BETWEEN</li>
|
|
|
|
* <li>NOT_BETWEEN</li>
|
|
|
|
* <li>EQUAL</li>
|
|
|
|
* <li>NOT_EQUAL</li>
|
|
|
|
* <li>GT</li>
|
|
|
|
* <li>LT</li>
|
|
|
|
* <li>GE</li>
|
|
|
|
* <li>LE</li>
|
|
|
|
* </ul>
|
|
|
|
* </p>
|
|
|
|
* @param formula1 - formula for the valued, compared with the cell
|
|
|
|
* @param formula2 - second formula (only used with
|
|
|
|
* {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
|
|
|
|
* {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
|
|
|
|
*/
|
|
|
|
public HSSFConditionalFormattingRule createConditionalFormattingRule(
|
|
|
|
byte comparisonOperation,
|
|
|
|
String formula1,
|
|
|
|
String formula2) {
|
|
|
|
|
|
|
|
HSSFWorkbook wb = _workbook;
|
|
|
|
CFRuleRecord rr = CFRuleRecord.create(wb, comparisonOperation, formula1, formula2);
|
|
|
|
return new HSSFConditionalFormattingRule(wb, rr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A factory method allowing to create a conditional formatting rule with a formula.<br>
|
|
|
|
*
|
Merged revisions 668156-671000 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r668257 | yegor | 2008-06-16 19:38:59 +0100 (Mon, 16 Jun 2008) | 1 line
TextShape.getMarginLeft() returned incorrect value. Added a unit test for text margins.
........
r668259 | yegor | 2008-06-16 19:40:51 +0100 (Mon, 16 Jun 2008) | 1 line
patch from bug #45177: Remove GPL reference in NOTICE
........
r669140 | nick | 2008-06-18 12:35:04 +0100 (Wed, 18 Jun 2008) | 1 line
A partial fix for bug #30978, but something still remains, which seems to be related to changing the ptg
........
r669456 | nick | 2008-06-19 12:47:48 +0100 (Thu, 19 Jun 2008) | 1 line
Improved HWPF Range.replaceText, from N. Hira in bug #45001
........
r669658 | josh | 2008-06-19 20:07:20 +0100 (Thu, 19 Jun 2008) | 1 line
Fix for bug 45234 - Removed incorrect shared formula conversion in CFRuleRecord
........
r669809 | josh | 2008-06-20 08:10:03 +0100 (Fri, 20 Jun 2008) | 1 line
Fix for bug 30978 - small re-arrangement of class Ptg hierarchy for DeletedRef3DPtg and DeletedArea3DPtg. Similar to c664220
........
r670190 | yegor | 2008-06-21 13:41:34 +0100 (Sat, 21 Jun 2008) | 1 line
started a new section for poi-3.2 family, updated release date of 3.2-FINAL
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674287 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 08:11:37 -04:00
|
|
|
* The formatting rules are applied by Excel when the value of the formula not equal to 0.<p/>
|
|
|
|
* TODO - formulas containing cell references are currently not parsed properly
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648417 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r648156 | yegor | 2008-04-15 08:54:20 +0100 (Tue, 15 Apr 2008) | 1 line
TextShape is a common superclass of all shapes that can hold text. The subclasses are TextBox and AutoShape.
........
r648203 | yegor | 2008-04-15 11:05:22 +0100 (Tue, 15 Apr 2008) | 1 line
start improving handling of resources in HSLF. PPFont object represents a font in a presenatation.
........
r648274 | yegor | 2008-04-15 16:11:13 +0100 (Tue, 15 Apr 2008) | 1 line
TextSpecInfoAtom is present in PPT 2003+. When the text is changed we must update this record, otherwise the ppt becomes corrupted
........
r648276 | yegor | 2008-04-15 16:12:58 +0100 (Tue, 15 Apr 2008) | 1 line
Improved factoring of ppt objects. For ppt tabels Slide.getShapes() returns the Table object (was ShapeGroup)
........
r648303 | nick | 2008-04-15 17:00:50 +0100 (Tue, 15 Apr 2008) | 1 line
Nice and small change here... Update the formula parser code to use usermodel.HSSFWorkbook instead of model.Workbook. This should keep things a bit cleaner, and make it much easier for the formula code to work with XSSF
........
r648334 | josh | 2008-04-15 18:07:06 +0100 (Tue, 15 Apr 2008) | 1 line
Conditional Formatting (30311) - API improvements, added HSSFSheetConditionalFormatting
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@648444 13f79535-47bb-0310-9956-ffa450edef68
2008-04-15 18:47:30 -04:00
|
|
|
* @param formula - formula for the valued, compared with the cell
|
|
|
|
*/
|
|
|
|
public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
|
|
|
|
HSSFWorkbook wb = _workbook;
|
|
|
|
CFRuleRecord rr = CFRuleRecord.create(wb, formula);
|
|
|
|
return new HSSFConditionalFormattingRule(wb, rr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a copy of HSSFConditionalFormatting object to the sheet
|
|
|
|
* <p>This method could be used to copy HSSFConditionalFormatting object
|
|
|
|
* from one sheet to another. For example:
|
|
|
|
* <pre>
|
|
|
|
* HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
|
|
|
|
* newSheet.addConditionalFormatting(cf);
|
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* @param cf HSSFConditionalFormatting object
|
|
|
|
* @return index of the new Conditional Formatting object
|
|
|
|
*/
|
|
|
|
public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
|
|
|
|
CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
|
|
|
|
|
|
|
|
return _sheet.addConditionalFormatting(cfraClone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows to add a new Conditional Formatting set to the sheet.
|
|
|
|
*
|
|
|
|
* @param regions - list of rectangular regions to apply conditional formatting rules
|
|
|
|
* @param cfRules - set of up to three conditional formatting rules
|
|
|
|
*
|
|
|
|
* @return index of the newly created Conditional Formatting object
|
|
|
|
*/
|
|
|
|
|
|
|
|
public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) {
|
|
|
|
if (regions == null) {
|
|
|
|
throw new IllegalArgumentException("regions must not be null");
|
|
|
|
}
|
|
|
|
if (cfRules == null) {
|
|
|
|
throw new IllegalArgumentException("cfRules must not be null");
|
|
|
|
}
|
|
|
|
if (cfRules.length == 0) {
|
|
|
|
throw new IllegalArgumentException("cfRules must not be empty");
|
|
|
|
}
|
|
|
|
if (cfRules.length > 3) {
|
|
|
|
throw new IllegalArgumentException("Number of rules must not exceed 3");
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRuleRecord[] rules = new CFRuleRecord[cfRules.length];
|
|
|
|
for (int i = 0; i != cfRules.length; i++) {
|
|
|
|
rules[i] = cfRules[i].getCfRuleRecord();
|
|
|
|
}
|
|
|
|
CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
|
|
|
|
return _sheet.addConditionalFormatting(cfra);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int addConditionalFormatting(Region[] regions,
|
|
|
|
HSSFConditionalFormattingRule rule1)
|
|
|
|
{
|
|
|
|
return addConditionalFormatting(regions,
|
|
|
|
new HSSFConditionalFormattingRule[]
|
|
|
|
{
|
|
|
|
rule1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public int addConditionalFormatting(Region[] regions,
|
|
|
|
HSSFConditionalFormattingRule rule1,
|
|
|
|
HSSFConditionalFormattingRule rule2)
|
|
|
|
{
|
|
|
|
return addConditionalFormatting(regions,
|
|
|
|
new HSSFConditionalFormattingRule[]
|
|
|
|
{
|
|
|
|
rule1, rule2
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public int addConditionalFormatting(Region[] regions,
|
|
|
|
HSSFConditionalFormattingRule rule1,
|
|
|
|
HSSFConditionalFormattingRule rule2,
|
|
|
|
HSSFConditionalFormattingRule rule3)
|
|
|
|
{
|
|
|
|
return addConditionalFormatting(regions,
|
|
|
|
new HSSFConditionalFormattingRule[]
|
|
|
|
{
|
|
|
|
rule1, rule2, rule3
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gets Conditional Formatting object at a particular index
|
|
|
|
*
|
|
|
|
* @param index
|
|
|
|
* of the Conditional Formatting object to fetch
|
|
|
|
* @return Conditional Formatting object
|
|
|
|
*/
|
|
|
|
public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
|
|
|
|
CFRecordsAggregate cf = _sheet.getCFRecordsAggregateAt(index);
|
|
|
|
if (cf == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new HSSFConditionalFormatting(_workbook, cf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return number of Conditional Formatting objects of the sheet
|
|
|
|
*/
|
|
|
|
public int getNumConditionalFormattings() {
|
|
|
|
return _sheet.getNumConditionalFormattings();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* removes a Conditional Formatting object by index
|
|
|
|
* @param index of a Conditional Formatting object to remove
|
|
|
|
*/
|
|
|
|
public void removeConditionalFormatting(int index) {
|
|
|
|
_sheet.removeConditionalFormatting(index);
|
|
|
|
}
|
|
|
|
}
|