From 844d1de676766206bd4ed38daf6b1088a7829621 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Wed, 26 Mar 2008 05:29:08 +0000 Subject: [PATCH] more javadoc + clean-up from Dmitriy (bug 30311 att 21711) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@641157 13f79535-47bb-0310-9956-ffa450edef68 --- .../record/aggregates/CFRecordsAggregate.java | 223 +++--- .../usermodel/HSSFConditionalFormatting.java | 122 +++- .../apache/poi/hssf/usermodel/HSSFSheet.java | 666 +++++++++--------- 3 files changed, 523 insertions(+), 488 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java index 78d1ecbd33..d6e81c7ea2 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java @@ -35,54 +35,55 @@ import org.apache.poi.util.POILogger; * @author Dmitriy Kumshayev * */ -public class CFRecordsAggregate extends Record +public final class CFRecordsAggregate extends Record { - public final static short sid = -2008; - - private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class); - - private CFHeaderRecord header; - - // List of CFRuleRecord objects - private List rules; - - public CFRecordsAggregate() - { - header = null; - rules = new ArrayList(3); - } - - /** - * Create CFRecordsAggregate from a list of CF Records - * @param recs - list of {@link Record} objects - * @param offset - position of {@link CFHeaderRecord} object in the list of Record objects - * @return CFRecordsAggregate object - */ - public static CFRecordsAggregate createCFAggregate(List recs, int offset) - { - CFRecordsAggregate cfRecords = new CFRecordsAggregate(); - ArrayList records = new ArrayList(4); - - int count = 0; - Record rec = ( Record ) recs.get(offset++); - - if (rec.getSid() == CFHeaderRecord.sid) - { - records.add(rec); - cfRecords.header = (CFHeaderRecord)rec; - - int nRules = cfRecords.header.getNumberOfConditionalFormats(); - int rulesCount = 0; - while( offset0 ) { header.setNumberOfConditionalFormats(rules.size()); - pos += (( Record ) header).serialize(pos, data); + pos += (( Record ) header).serialize(pos, data); - for(Iterator itr = rules.iterator(); itr.hasNext();) - { - pos += (( Record ) itr.next()).serialize(pos, data); - } + for(Iterator itr = rules.iterator(); itr.hasNext();) + { + pos += (( Record ) itr.next()).serialize(pos, data); + } } - return pos - offset; + return pos - offset; } - + protected void validateSid(short id) { // do nothing here @@ -179,21 +180,21 @@ public class CFRecordsAggregate extends Record */ public int getRecordSize() { - int size = 0; - if( header != null) - { - size += header.getRecordSize(); - } - if( rules != null) - { - for(Iterator irecs = rules.iterator(); irecs.hasNext(); ) - { - size += (( Record ) irecs.next()).getRecordSize(); - } - } - return size; - } - + int size = 0; + if( header != null) + { + size += header.getRecordSize(); + } + if( rules != null) + { + for(Iterator irecs = rules.iterator(); irecs.hasNext(); ) + { + size += (( Record ) irecs.next()).getRecordSize(); + } + } + return size; + } + /** * String representation of CFRecordsAggregate */ @@ -206,19 +207,15 @@ public class CFRecordsAggregate extends Record { buffer.append(header.toString()); } - if( rules != null ) + for(int i=0; i + *
  • + * to make a copy HSSFConditionalFormatting settings. + *
  • + * * * For example: *
    @@ -36,7 +42,15 @@ import org.apache.poi.hssf.util.Region;
      * newSheet.addConditionalFormatting(cf);
      * 
    * + *
  • + * or to modify existing Conditional Formatting settings (formatting regions and/or rules). + *
  • + * + * + * Use {@link HSSFSheet#getConditionalFormattingAt(int)} to get access to an instance of this class. + *

    * To create a new Conditional Formatting set use the following approach: + * *

      * // Create pattern with red background
      * HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting();
    @@ -70,23 +84,29 @@ import org.apache.poi.hssf.util.Region;
      * 
      * @author Dmitriy Kumshayev
      */
    -public class HSSFConditionalFormatting
    +public final class HSSFConditionalFormatting
     {
    -	HSSFSheet sheet;
    -	CFRecordsAggregate cfAggregate;
    -	
    -	protected HSSFConditionalFormatting(HSSFSheet sheet)
    -	{
    -		this.sheet = sheet;
    -		this.cfAggregate = new CFRecordsAggregate();
    +	private final HSSFSheet sheet;
    +	private final CFRecordsAggregate cfAggregate;
    +
    +	HSSFConditionalFormatting(HSSFSheet sheet) {
    +		this(sheet, new CFRecordsAggregate());
     	}
    -	
    -	protected HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
    +
    +	HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate)
     	{
    +		if(sheet == null) {
    +			throw new IllegalArgumentException("sheet must not be null");
    +		}
    +		if(cfAggregate == null) {
    +			throw new IllegalArgumentException("cfAggregate must not be null");
    +		}
     		this.sheet = sheet;
     		this.cfAggregate = cfAggregate;
     	}
    -	
    +	CFRecordsAggregate getCFRecordsAggregate() {
    +		return cfAggregate;
    +	}
     
     	public void setFormattingRegions(Region[] regions)
     	{
    @@ -97,35 +117,65 @@ public class HSSFConditionalFormatting
     		}
     	}
     
    +	/**
    +	 * @return array of Regions. never null
    +	 */
     	public Region[] getFormattingRegions()
     	{
     		CFHeaderRecord cfh = cfAggregate.getHeader();
    -		
    +
     		List cellRanges = cfh.getCellRanges();
    -		
    -		if (cellRanges != null)
    -		{
    -			return toRegionArray(cellRanges);
    -		}
    -		return null;
    +
    +		return toRegionArray(cellRanges);
     	}
    -	
    -	public void setConditionalFormat(int idx, HSSFConditionalFormattingRule cfRule)
    +
    +	/**
    +	 * set a Conditional Formatting rule at position idx. 
    +	 * Excel allows to create up to 3 Conditional Formatting rules.
    +	 * This method can be useful to modify existing  Conditional Formatting rules.
    +	 * 
    +	 * @param idx position of the rule. Should be between 0 and 2.
    +	 * @param cfRule - Conditional Formatting rule
    +	 */
    +	public void setRule(int idx, HSSFConditionalFormattingRule cfRule)
     	{
    +	    if (idx < 0 || idx > 2) {
    +	        throw new IllegalArgumentException("idx must be between 0 and 2 but was (" 
    +	                + idx + ")");
    +	    }
     		cfAggregate.getRules().set(idx, cfRule);
     	}
     
    -	public void addConditionalFormat(HSSFConditionalFormattingRule cfRule)
    +	/**
    +	 * add a Conditional Formatting rule. 
    +	 * Excel allows to create up to 3 Conditional Formatting rules.
    +	 * @param cfRule - Conditional Formatting rule
    +	 */
    +	public void addRule(HSSFConditionalFormattingRule cfRule)
     	{
     		cfAggregate.getRules().add(cfRule);
     	}
    -	
    -	public HSSFConditionalFormattingRule getConditionalFormat(int idx)
    +
    +	/**
    +	 * get a Conditional Formatting rule at position idx. 
    +	 * @param idx
    +	 * @return a Conditional Formatting rule at position idx.
    +	 */
    +	public HSSFConditionalFormattingRule getRule(int idx)
     	{
     		CFRuleRecord ruleRecord = (CFRuleRecord)cfAggregate.getRules().get(idx);
     		return new HSSFConditionalFormattingRule(sheet.workbook, ruleRecord);
     	}
    -	
    +
    +	/**
    +	 * @return number of Conditional Formatting rules.
    +	 */
    +	public int getNumbOfRules()
    +	{
    +		return cfAggregate.getRules().size();
    +	}
    +
    +
     	/**
     	 * Do all possible cell merges between cells of the list so that:
    *
  • if a cell range is completely inside of another cell range, it gets removed from the list @@ -136,11 +186,11 @@ public class HSSFConditionalFormatting private static List mergeCellRanges(List cellRangeList) { boolean merged = false; - + do { merged = false; - + if( cellRangeList.size()>1 ) { for( int i=0; i protection enabled; false => protection disabled - */ - public boolean getProtect() { - return getSheet().isProtected()[0]; - } - - /** - * @return hashed password - */ - public short getPassword() { - return getSheet().getPassword().getPassword(); - } - - /** - * Answer whether object protection is enabled or disabled - * @return true => protection enabled; false => protection disabled - */ - public boolean getObjectProtect() { - return getSheet().isProtected()[1]; - } - - /** - * Answer whether scenario protection is enabled or disabled - * @return true => protection enabled; false => protection disabled - */ - public boolean getScenarioProtect() { - return getSheet().isProtected()[2]; - } - - /** - * Sets the protection on enabled or disabled - * @param protect true => protection enabled; false => protection disabled + /** + * Answer whether protection is enabled or disabled + * @return true => protection enabled; false => protection disabled + */ + public boolean getProtect() { + return getSheet().isProtected()[0]; + } + + /** + * @return hashed password + */ + public short getPassword() { + return getSheet().getPassword().getPassword(); + } + + /** + * Answer whether object protection is enabled or disabled + * @return true => protection enabled; false => protection disabled + */ + public boolean getObjectProtect() { + return getSheet().isProtected()[1]; + } + + /** + * Answer whether scenario protection is enabled or disabled + * @return true => protection enabled; false => protection disabled + */ + public boolean getScenarioProtect() { + return getSheet().isProtected()[2]; + } + + /** + * Sets the protection on enabled or disabled + * @param protect true => protection enabled; false => protection disabled * @deprecated use protectSheet(String, boolean, boolean) - */ - public void setProtect(boolean protect) { - getSheet().getProtect().setProtect(protect); - } + */ + public void setProtect(boolean protect) { + getSheet().getProtect().setProtect(protect); + } /** * Sets the protection enabled as well as the password @@ -1069,29 +1062,29 @@ public class HSSFSheet sclRecord.setDenominator((short)denominator); getSheet().setSCLRecord(sclRecord); } - + /** - * The top row in the visible view when the sheet is - * first viewed after opening it in a viewer + * The top row in the visible view when the sheet is + * first viewed after opening it in a viewer * @return short indicating the rownum (0 based) of the top row */ - public short getTopRow() + public short getTopRow() { - return sheet.getTopRow(); + return sheet.getTopRow(); } - + /** - * The left col in the visible view when the sheet is - * first viewed after opening it in a viewer + * The left col in the visible view when the sheet is + * first viewed after opening it in a viewer * @return short indicating the rownum (0 based) of the top row */ - public short getLeftCol() + public short getLeftCol() { - return sheet.getLeftCol(); + return sheet.getLeftCol(); } - + /** - * Sets desktop window pane display area, when the + * Sets desktop window pane display area, when the * file is first opened in a viewer. * @param toprow the top row to show in desktop window pane * @param leftcol the left column to show in desktop window pane @@ -1101,49 +1094,49 @@ public class HSSFSheet this.sheet.setLeftCol((short)leftcol); } - /** - * Shifts the merged regions left or right depending on mode - *

    - * TODO: MODE , this is only row specific - * @param startRow - * @param endRow - * @param n - * @param isRow - */ - protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) { - List shiftedRegions = new ArrayList(); - //move merged regions completely if they fall within the new region boundaries when they are shifted - for (int i = 0; i < this.getNumMergedRegions(); i++) { - Region merged = this.getMergedRegionAt(i); - - boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow); - boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow); - - //dont check if it's not within the shifted area - if (! (inStart && inEnd)) continue; - - //only shift if the region outside the shifted rows is not merged too - if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){ - merged.setRowFrom(merged.getRowFrom()+n); - merged.setRowTo(merged.getRowTo()+n); - //have to remove/add it back - shiftedRegions.add(merged); - this.removeMergedRegion(i); - i = i -1; // we have to back up now since we removed one - - } + /** + * Shifts the merged regions left or right depending on mode + *

    + * TODO: MODE , this is only row specific + * @param startRow + * @param endRow + * @param n + * @param isRow + */ + protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) { + List shiftedRegions = new ArrayList(); + //move merged regions completely if they fall within the new region boundaries when they are shifted + for (int i = 0; i < this.getNumMergedRegions(); i++) { + Region merged = this.getMergedRegionAt(i); + + boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow); + boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow); + + //dont check if it's not within the shifted area + if (! (inStart && inEnd)) continue; + + //only shift if the region outside the shifted rows is not merged too + if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){ + merged.setRowFrom(merged.getRowFrom()+n); + merged.setRowTo(merged.getRowTo()+n); + //have to remove/add it back + shiftedRegions.add(merged); + this.removeMergedRegion(i); + i = i -1; // we have to back up now since we removed one + + } - } + } - //readd so it doesn't get shifted again - Iterator iterator = shiftedRegions.iterator(); - while (iterator.hasNext()) { - Region region = (Region)iterator.next(); + //readd so it doesn't get shifted again + Iterator iterator = shiftedRegions.iterator(); + while (iterator.hasNext()) { + Region region = (Region)iterator.next(); - this.addMergedRegion(region); - } + this.addMergedRegion(region); + } - } + } /** * Shifts rows between startRow and endRow n number of rows. @@ -1160,7 +1153,7 @@ public class HSSFSheet * @param n the number of rows to shift */ public void shiftRows( int startRow, int endRow, int n ) { - shiftRows(startRow, endRow, n, false, false); + shiftRows(startRow, endRow, n, false, false); } /** @@ -1197,7 +1190,7 @@ public class HSSFSheet shiftMerged(startRow, endRow, n, true); sheet.shiftRowBreaks(startRow, endRow, n); - + for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc ) { HSSFRow row = getRow( rowNum ); @@ -1210,23 +1203,23 @@ public class HSSFSheet - // Removes the cells before over writting them. + // Removes the cells before over writting them. for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ ) { cell = row2Replace.getCell( col ); if ( cell != null ) row2Replace.removeCell( cell ); } - if (row == null) continue; // Nothing to do for this row - else { - if (copyRowHeight) { - row2Replace.setHeight(row.getHeight()); - } - - if (resetOriginalRowHeight) { - row.setHeight((short)0xff); - } - } + if (row == null) continue; // Nothing to do for this row + else { + if (copyRowHeight) { + row2Replace.setHeight(row.getHeight()); + } + + if (resetOriginalRowHeight) { + row.setHeight((short)0xff); + } + } for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ ) { cell = row.getCell( col ); @@ -1248,55 +1241,55 @@ public class HSSFSheet } if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 ); if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 ); - + // Update any formulas on this sheet that point to // rows which have been moved updateFormulasAfterShift(startRow, endRow, n); } - + /** * Called by shiftRows to update formulas on this sheet * to point to the new location of moved rows */ private void updateFormulasAfterShift(int startRow, int endRow, int n) { - // Need to look at every cell on the sheet - // Not just those that were moved + // Need to look at every cell on the sheet + // Not just those that were moved Iterator ri = rowIterator(); while(ri.hasNext()) { - HSSFRow r = (HSSFRow)ri.next(); - Iterator ci = r.cellIterator(); - while(ci.hasNext()) { - HSSFCell c = (HSSFCell)ci.next(); - if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { - // Since it's a formula cell, process the - // formula string, and look to see if - // it contains any references - FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook()); - fp.parse(); - - // Look for references, and update if needed - Ptg[] ptgs = fp.getRPNPtg(); - boolean changed = false; - for(int i=0; i 0) { - int[] returnValue = new int[count]; - Iterator iterator = sheet.getRowBreaks(); - int i = 0; - while (iterator.hasNext()) { - PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); - returnValue[i++] = (int)breakItem.main; - } - return returnValue; - } - return null; + //we can probably cache this information, but this should be a sparsely used function + int count = sheet.getNumRowBreaks(); + if (count > 0) { + int[] returnValue = new int[count]; + Iterator iterator = sheet.getRowBreaks(); + int i = 0; + while (iterator.hasNext()) { + PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); + returnValue[i++] = (int)breakItem.main; + } + return returnValue; + } + return null; } /** @@ -1457,29 +1450,29 @@ public class HSSFSheet * @return all the vertical page breaks, or null if there are no column page breaks */ public short[] getColumnBreaks(){ - //we can probably cache this information, but this should be a sparsely used function - int count = sheet.getNumColumnBreaks(); - if (count > 0) { - short[] returnValue = new short[count]; - Iterator iterator = sheet.getColumnBreaks(); - int i = 0; - while (iterator.hasNext()) { - PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); - returnValue[i++] = breakItem.main; - } - return returnValue; - } - return null; - } - - + //we can probably cache this information, but this should be a sparsely used function + int count = sheet.getNumColumnBreaks(); + if (count > 0) { + short[] returnValue = new short[count]; + Iterator iterator = sheet.getColumnBreaks(); + int i = 0; + while (iterator.hasNext()) { + PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); + returnValue[i++] = breakItem.main; + } + return returnValue; + } + return null; + } + + /** * Sets a page break at the indicated column * @param column */ public void setColumnBreak(short column) { - validateColumn(column); - sheet.setColumnBreak(column, (short)0, (short)65535); + validateColumn(column); + sheet.setColumnBreak(column, (short)0, (short)65535); } /** @@ -1488,33 +1481,33 @@ public class HSSFSheet * @return FIXME: Document this! */ public boolean isColumnBroken(short column) { - return sheet.isColumnBroken(column); + return sheet.isColumnBroken(column); } - + /** * Removes a page break at the indicated column * @param column */ public void removeColumnBreak(short column) { - sheet.removeColumnBreak(column); + sheet.removeColumnBreak(column); } - + /** * Runs a bounds check for row numbers * @param row */ protected void validateRow(int row) { - if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535"); - if (row < 0) throw new IllegalArgumentException("Minumum row number is 0"); + if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535"); + if (row < 0) throw new IllegalArgumentException("Minumum row number is 0"); } - + /** * Runs a bounds check for column numbers * @param column */ protected void validateColumn(short column) { - if (column > 255) throw new IllegalArgumentException("Maximum column number is 255"); - if (column < 0) throw new IllegalArgumentException("Minimum column number is 0"); + if (column > 255) throw new IllegalArgumentException("Maximum column number is 255"); + if (column < 0) throw new IllegalArgumentException("Minimum column number is 0"); } /** @@ -1559,7 +1552,7 @@ public class HSSFSheet agg.setPatriarch(patriarch); return patriarch; } - + /** * Returns the top-level drawing patriach, if there is * one. @@ -1573,32 +1566,32 @@ public class HSSFSheet * start from scratch! */ public HSSFPatriarch getDrawingPatriarch() { - book.findDrawingGroup(); - - // If there's now no drawing manager, then there's - // no drawing escher records on the workbook - if(book.getDrawingManager() == null) { - return null; - } - - int found = sheet.aggregateDrawingRecords( - book.getDrawingManager(), false - ); - if(found == -1) { - // Workbook has drawing stuff, but this sheet doesn't - return null; - } - - // Grab our aggregate record, and wire it up + book.findDrawingGroup(); + + // If there's now no drawing manager, then there's + // no drawing escher records on the workbook + if(book.getDrawingManager() == null) { + return null; + } + + int found = sheet.aggregateDrawingRecords( + book.getDrawingManager(), false + ); + if(found == -1) { + // Workbook has drawing stuff, but this sheet doesn't + return null; + } + + // Grab our aggregate record, and wire it up EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid); HSSFPatriarch patriarch = new HSSFPatriarch(this, agg); agg.setPatriarch(patriarch); - + // Have it process the records into high level objects // as best it can do (this step may eat anything // that isn't supported, you were warned...) agg.convertRecordsToUserModel(); - + // Return what we could cope with return patriarch; } @@ -1652,7 +1645,7 @@ public class HSSFSheet * @param style the style to set */ public void setDefaultColumnStyle(short column, HSSFCellStyle style) { - sheet.setColumn(column, new Short(style.getIndex()), null, null, null, null); + sheet.setColumn(column, new Short(style.getIndex()), null, null, null, null); } /** @@ -1673,13 +1666,13 @@ public class HSSFSheet * '0' looks to be a good choice. */ char defaultChar = '0'; - + /** * This is the multiple that the font height is scaled by when determining the * boundary of rotated text. */ double fontHeightMultiple = 2.0; - + FontRenderContext frc = new FontRenderContext(null, true, true); HSSFWorkbook wb = new HSSFWorkbook(book); @@ -1800,7 +1793,7 @@ public class HSSFSheet /** * Copy text attributes from the supplied HSSFFont to Java2D AttributedString */ - private void copyAttributes(HSSFFont font, AttributedString str, int startIdx, int endIdx){ + private void copyAttributes(HSSFFont font, AttributedString str, int startIdx, int endIdx) { str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx); str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints())); if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx); @@ -1833,86 +1826,86 @@ public class HSSFSheet /** - * A factory method allowing to create a conditional formatting rule - * with a cell comparison operator and + * A factory method allowing to create a conditional formatting rule + * with a cell comparison operator and * formatting rules such as font format, border format and pattern format - * + * * @param comparisonOperation - one of the following values:

    - *

  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}
  • - *

    + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}
  • + *

    * @param formula1 - formula for the valued, compared with the cell - * @param formula2 - second formula (only used with + * @param formula2 - second formula (only used with * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and - * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) + * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) * @param fontFmt - font formatting rules * @param bordFmt - border formatting rules * @param patternFmt - pattern formatting rules * @return - * + * */ public HSSFConditionalFormattingRule createConditionalFormattingRule( - byte comparisonOperation, - String formula1, - String formula2, - HSSFFontFormatting fontFmt, - HSSFBorderFormatting bordFmt, - HSSFPatternFormatting patternFmt) + byte comparisonOperation, + String formula1, + String formula2, + HSSFFontFormatting fontFmt, + HSSFBorderFormatting bordFmt, + HSSFPatternFormatting patternFmt) { - HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); - cf.setFontFormatting(fontFmt); - cf.setBorderFormatting(bordFmt); - cf.setPatternFormatting(patternFmt); - cf.setCellComparisonCondition(comparisonOperation, formula1, formula2); - return cf; + HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); + cf.setFontFormatting(fontFmt); + cf.setBorderFormatting(bordFmt); + cf.setPatternFormatting(patternFmt); + cf.setCellComparisonCondition(comparisonOperation, formula1, formula2); + return cf; } /** - * A factory method allowing to create a conditional formatting rule with a formula + * A factory method allowing to create a conditional formatting rule with a formula * and formatting rules such as font format, border format and pattern format.
    - * - * The formatting rules are applied by Excel when the value of the formula not equal to 0. - * + * + * The formatting rules are applied by Excel when the value of the formula not equal to 0. + * * @param comparisonOperation - one of the following values:

    - *

  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}
  • - *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}
  • - *

    + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}
  • + *
  • {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}
  • + *

    * @param formula1 - formula for the valued, compared with the cell - * @param formula2 - second formula (only used with + * @param formula2 - second formula (only used with * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and - * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) + * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) * @param fontFmt - font formatting rules * @param bordFmt - border formatting rules * @param patternFmt - pattern formatting rules * @return - * + * */ public HSSFConditionalFormattingRule createConditionalFormattingRule( - String formula, - HSSFFontFormatting fontFmt, - HSSFBorderFormatting bordFmt, - HSSFPatternFormatting patternFmt) + String formula, + HSSFFontFormatting fontFmt, + HSSFBorderFormatting bordFmt, + HSSFPatternFormatting patternFmt) { - HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); - cf.setFontFormatting(fontFmt); - cf.setBorderFormatting(bordFmt); - cf.setPatternFormatting(patternFmt); - cf.setFormulaCondition(formula); - return cf; + HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); + cf.setFontFormatting(fontFmt); + cf.setBorderFormatting(bordFmt); + cf.setPatternFormatting(patternFmt); + cf.setFormulaCondition(formula); + return cf; } - + /** * Adds a copy of HSSFConditionalFormatting object to the sheet *

    This method could be used to copy HSSFConditionalFormatting object @@ -1920,72 +1913,71 @@ public class HSSFSheet *

           * 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 ) { - HSSFConditionalFormatting cfClone = new HSSFConditionalFormatting(this,cf.cfAggregate.cloneCFAggregate()); - cfClone.sheet=this; - return sheet.addConditionalFormatting(cfClone.cfAggregate); + 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 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 ) { - HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this); - cf.setFormattingRegions(regions); - if( cfRules != null ) - { - for( int i=0; i!= cfRules.length; i++ ) - { - cf.addConditionalFormat(cfRules[i]); - } - } - return sheet.addConditionalFormatting(cf.cfAggregate); + HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this); + cf.setFormattingRegions(regions); + if( cfRules != null ) + { + for( int i=0; i!= cfRules.length; i++ ) + { + cf.addRule(cfRules[i]); + } + } + return sheet.addConditionalFormatting(cf.getCFRecordsAggregate()); } - - /** - * 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 new HSSFConditionalFormatting(this,cf); - } - return null; - } - - /** - * @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); - } + /** + * 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 new HSSFConditionalFormatting(this,cf); + } + return null; + } + + /** + * @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); + } } -- 2.39.5