From: Nick Burch
- *
- *
- *
+ *
This method could be used to copy HSSFConditionalFormatting object - * from one sheet to another. For example: - *
- * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); - * newSheet.addConditionalFormatting(cf); - *- * - * @param cf HSSFConditionalFormatting object - * @return index of the new Conditional Formatting object - */ - public int addConditionalFormatting( HSSFConditionalFormatting cf ) { - CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); - - return _conditionalFormattingTable.add(cfraClone); - } + + /** + * Adds a copy of HSSFConditionalFormatting object to the sheet + *
This method could be used to copy HSSFConditionalFormatting object + * from one sheet to another. For example: + *
+ * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); + * newSheet.addConditionalFormatting(cf); + *+ * + * @param cf HSSFConditionalFormatting object + * @return index of the new Conditional Formatting object + */ + public int addConditionalFormatting( HSSFConditionalFormatting cf ) { + CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); + + return _conditionalFormattingTable.add(cfraClone); + } public int addConditionalFormatting( ConditionalFormatting cf ) { return addConditionalFormatting((HSSFConditionalFormatting)cf); } - /** - * @deprecated use CellRangeAddress instead of Region - */ - public int addConditionalFormatting(org.apache.poi.ss.util.Region[] regions, HSSFConditionalFormattingRule[] cfRules) { - return addConditionalFormatting(org.apache.poi.ss.util.Region.convertRegionsToCellRanges(regions), cfRules); - } - /** - * 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(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) { - if (regions == null) { - throw new IllegalArgumentException("regions must not be null"); - } - for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97); - - 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"); - } - - CFRuleBase[] rules = new CFRuleBase[cfRules.length]; - for (int i = 0; i != cfRules.length; i++) { - rules[i] = cfRules[i].getCfRuleRecord(); - } - CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules); - return _conditionalFormattingTable.add(cfra); - } + /** + * @deprecated use CellRangeAddress instead of Region + */ + public int addConditionalFormatting(org.apache.poi.ss.util.Region[] regions, HSSFConditionalFormattingRule[] cfRules) { + return addConditionalFormatting(org.apache.poi.ss.util.Region.convertRegionsToCellRanges(regions), cfRules); + } + /** + * 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(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) { + if (regions == null) { + throw new IllegalArgumentException("regions must not be null"); + } + for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97); + + 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"); + } + + CFRuleBase[] rules = new CFRuleBase[cfRules.length]; + for (int i = 0; i != cfRules.length; i++) { + rules[i] = cfRules[i].getCfRuleRecord(); + } + CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules); + return _conditionalFormattingTable.add(cfra); + } public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) { HSSFConditionalFormattingRule[] hfRules; @@ -179,70 +178,61 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor return addConditionalFormatting(regions, hfRules); } - public int addConditionalFormatting(CellRangeAddress[] regions, - HSSFConditionalFormattingRule rule1) - { - return addConditionalFormatting(regions, - rule1 == null ? null : new HSSFConditionalFormattingRule[] - { - rule1 - }); - } + public int addConditionalFormatting(CellRangeAddress[] regions, + HSSFConditionalFormattingRule rule1) { + return addConditionalFormatting(regions, rule1 == null ? + null : new HSSFConditionalFormattingRule[] { rule1 } + ); + } public int addConditionalFormatting(CellRangeAddress[] regions, - ConditionalFormattingRule rule1) - { + ConditionalFormattingRule rule1) { return addConditionalFormatting(regions, (HSSFConditionalFormattingRule)rule1); } - public int addConditionalFormatting(CellRangeAddress[] regions, - HSSFConditionalFormattingRule rule1, - HSSFConditionalFormattingRule rule2) - { - return addConditionalFormatting(regions, - new HSSFConditionalFormattingRule[] - { - rule1, rule2 - }); - } + public int addConditionalFormatting(CellRangeAddress[] regions, + HSSFConditionalFormattingRule rule1, + HSSFConditionalFormattingRule rule2) { + return addConditionalFormatting(regions, + new HSSFConditionalFormattingRule[] { rule1, rule2 }); + } public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule rule1, - ConditionalFormattingRule rule2) - { + ConditionalFormattingRule rule2) { return addConditionalFormatting(regions, (HSSFConditionalFormattingRule)rule1, (HSSFConditionalFormattingRule)rule2 - ); - } - - /** - * 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 = _conditionalFormattingTable.get(index); - if (cf == null) { - return null; - } - return new HSSFConditionalFormatting(_sheet, cf); - } - - /** - * @return number of Conditional Formatting objects of the sheet - */ - public int getNumConditionalFormattings() { - return _conditionalFormattingTable.size(); - } - - /** - * removes a Conditional Formatting object by index - * @param index of a Conditional Formatting object to remove - */ - public void removeConditionalFormatting(int index) { - _conditionalFormattingTable.remove(index); - } + ); + } + + /** + * 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 = _conditionalFormattingTable.get(index); + if (cf == null) { + return null; + } + return new HSSFConditionalFormatting(_sheet, cf); + } + + /** + * @return number of Conditional Formatting objects of the sheet + */ + public int getNumConditionalFormattings() { + return _conditionalFormattingTable.size(); + } + + /** + * removes a Conditional Formatting object by index + * @param index of a Conditional Formatting object to remove + */ + public void removeConditionalFormatting(int index) { + _conditionalFormattingTable.remove(index); + } }