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
This commit is contained in:
Josh Micich 2008-03-26 05:29:08 +00:00
parent 82f40767dc
commit 3ecb3c4c95
3 changed files with 509 additions and 474 deletions

View File

@ -35,54 +35,55 @@ import org.apache.poi.util.POILogger;
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
* *
*/ */
public class CFRecordsAggregate extends Record public final class CFRecordsAggregate extends Record
{ {
public final static short sid = -2008; public final static short sid = -2008; // not a real BIFF record
private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class); private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
private CFHeaderRecord header; private CFHeaderRecord header;
// List of CFRuleRecord objects
private final 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 pOffset)
{
int offset = pOffset;
CFRecordsAggregate cfRecords = new CFRecordsAggregate();
ArrayList records = new ArrayList(4);
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( offset<recs.size() &&
(rec = (Record)recs.get(offset++)).getSid() == CFRuleRecord.sid &&
rec instanceof CFRuleRecord &&
rulesCount++ < nRules
)
{
records.add(rec);
cfRecords.rules.add(rec);
}
// 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( offset<recs.size() &&
(rec = (Record)recs.get(offset++)).getSid() == CFRuleRecord.sid &&
rec instanceof CFRuleRecord &&
rulesCount++ < nRules
)
{
records.add(rec);
cfRecords.rules.add(rec);
}
if (nRules != cfRecords.rules.size()) if (nRules != cfRecords.rules.size())
{ {
if (log.check(POILogger.DEBUG)) if (log.check(POILogger.DEBUG))
@ -93,66 +94,66 @@ public class CFRecordsAggregate extends Record
cfRecords.header.setNumberOfConditionalFormats(nRules); cfRecords.header.setNumberOfConditionalFormats(nRules);
} }
} }
return cfRecords; return cfRecords;
} }
/** /**
* Create a deep clone of the record * Create a deep clone of the record
* @return * @return
*/ */
public CFRecordsAggregate cloneCFAggregate() public CFRecordsAggregate cloneCFAggregate()
{ {
ArrayList records = new ArrayList(this.rules.size()+1); ArrayList records = new ArrayList(this.rules.size()+1);
records.add(this.header.clone()); records.add(this.header.clone());
for (int i=0; i<this.rules.size();i++) for (int i=0; i<this.rules.size();i++)
{ {
Record rec = (Record)((Record)this.rules.get(i)).clone(); Record rec = (Record)((Record)this.rules.get(i)).clone();
records.add(rec); records.add(rec);
} }
return createCFAggregate(records, 0); return createCFAggregate(records, 0);
} }
/** You never fill an aggregate */ /** You never fill an aggregate */
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
} }
public short getSid() public short getSid()
{ {
return sid; return sid;
} }
/** /**
* called by the class that is responsible for writing this sucker. * called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a * Subclasses should implement this so that their data is passed back in a
* byte array. * byte array.
* *
* @param offset to begin writing at * @param offset to begin writing at
* @param data byte array containing instance data * @param data byte array containing instance data
* @return number of bytes written * @return number of bytes written
*/ */
public int serialize(int offset, byte[] data) public int serialize(int offset, byte[] data)
{ {
int pos = offset; int pos = offset;
if( header != null && rules.size()>0 ) if( header != null && rules.size()>0 )
{ {
header.setNumberOfConditionalFormats(rules.size()); header.setNumberOfConditionalFormats(rules.size());
pos += (( Record ) header).serialize(pos, data); pos += (( Record ) header).serialize(pos, data);
for(Iterator itr = rules.iterator(); itr.hasNext();) for(Iterator itr = rules.iterator(); itr.hasNext();)
{ {
pos += (( Record ) itr.next()).serialize(pos, data); pos += (( Record ) itr.next()).serialize(pos, data);
} }
} }
return pos - offset; return pos - offset;
} }
protected void validateSid(short id) protected void validateSid(short id)
{ {
// do nothing here // do nothing here
@ -179,21 +180,21 @@ public class CFRecordsAggregate extends Record
*/ */
public int getRecordSize() public int getRecordSize()
{ {
int size = 0; int size = 0;
if( header != null) if( header != null)
{ {
size += header.getRecordSize(); size += header.getRecordSize();
} }
if( rules != null) if( rules != null)
{ {
for(Iterator irecs = rules.iterator(); irecs.hasNext(); ) for(Iterator irecs = rules.iterator(); irecs.hasNext(); )
{ {
size += (( Record ) irecs.next()).getRecordSize(); size += (( Record ) irecs.next()).getRecordSize();
} }
} }
return size; return size;
} }
/** /**
* String representation of CFRecordsAggregate * String representation of CFRecordsAggregate
*/ */
@ -206,19 +207,15 @@ public class CFRecordsAggregate extends Record
{ {
buffer.append(header.toString()); buffer.append(header.toString());
} }
if( rules != null ) for(int i=0; i<rules.size(); i++)
{ {
for(int i=0; i<rules.size(); i++) CFRuleRecord cfRule = (CFRuleRecord)rules.get(i);
if(cfRule!=null)
{ {
CFRuleRecord cfRule = (CFRuleRecord)rules.get(i); buffer.append(cfRule.toString());
if(cfRule!=null)
{
buffer.append(cfRule.toString());
}
} }
} }
buffer.append("[/CF]\n"); buffer.append("[/CF]\n");
return buffer.toString(); return buffer.toString();
} }
} }

View File

@ -27,8 +27,14 @@ import org.apache.poi.hssf.util.Region;
/** /**
* HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting. * HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting.
* The class is not intended to be used explicitly except cases when there is a need *
* to make a copy HSSFConditionalFormatting settings for some reason. * The class can be used
*
* <UL>
* <LI>
* to make a copy HSSFConditionalFormatting settings.
* </LI>
*
* *
* For example: * For example:
* <PRE> * <PRE>
@ -36,7 +42,15 @@ import org.apache.poi.hssf.util.Region;
* newSheet.addConditionalFormatting(cf); * newSheet.addConditionalFormatting(cf);
* </PRE> * </PRE>
* *
* <LI>
* or to modify existing Conditional Formatting settings (formatting regions and/or rules).
* </LI>
* </UL>
*
* Use {@link HSSFSheet#getConditionalFormattingAt(int)} to get access to an instance of this class.
* <P>
* To create a new Conditional Formatting set use the following approach: * To create a new Conditional Formatting set use the following approach:
*
* <PRE> * <PRE>
* // Create pattern with red background * // Create pattern with red background
* HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting(); * HSSFPatternFormatting patternFormatting = new HSSFPatternFormatting();
@ -70,23 +84,29 @@ import org.apache.poi.hssf.util.Region;
* *
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public class HSSFConditionalFormatting public final class HSSFConditionalFormatting
{ {
HSSFSheet sheet; private final HSSFSheet sheet;
CFRecordsAggregate cfAggregate; private final CFRecordsAggregate cfAggregate;
protected HSSFConditionalFormatting(HSSFSheet sheet) HSSFConditionalFormatting(HSSFSheet sheet) {
{ this(sheet, new CFRecordsAggregate());
this.sheet = sheet;
this.cfAggregate = 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.sheet = sheet;
this.cfAggregate = cfAggregate; this.cfAggregate = cfAggregate;
} }
CFRecordsAggregate getCFRecordsAggregate() {
return cfAggregate;
}
public void setFormattingRegions(Region[] regions) public void setFormattingRegions(Region[] regions)
{ {
@ -97,35 +117,65 @@ public class HSSFConditionalFormatting
} }
} }
/**
* @return array of <tt>Region</tt>s. never <code>null</code>
*/
public Region[] getFormattingRegions() public Region[] getFormattingRegions()
{ {
CFHeaderRecord cfh = cfAggregate.getHeader(); CFHeaderRecord cfh = cfAggregate.getHeader();
List cellRanges = cfh.getCellRanges(); List cellRanges = cfh.getCellRanges();
if (cellRanges != null) return toRegionArray(cellRanges);
{
return toRegionArray(cellRanges);
}
return null;
} }
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); 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); 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); CFRuleRecord ruleRecord = (CFRuleRecord)cfAggregate.getRules().get(idx);
return new HSSFConditionalFormattingRule(sheet.workbook, ruleRecord); 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:<br> * Do all possible cell merges between cells of the list so that:<br>
* <li>if a cell range is completely inside of another cell range, it gets removed from the list * <li>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) private static List mergeCellRanges(List cellRangeList)
{ {
boolean merged = false; boolean merged = false;
do do
{ {
merged = false; merged = false;
if( cellRangeList.size()>1 ) if( cellRangeList.size()>1 )
{ {
for( int i=0; i<cellRangeList.size(); i++) for( int i=0; i<cellRangeList.size(); i++)
@ -149,7 +199,7 @@ public class HSSFConditionalFormatting
for( int j=i+1; j<cellRangeList.size(); j++) for( int j=i+1; j<cellRangeList.size(); j++)
{ {
CellRange range2 = (CellRange)cellRangeList.get(j); CellRange range2 = (CellRange)cellRangeList.get(j);
switch(range1.intersect(range2)) switch(range1.intersect(range2))
{ {
case CellRange.NO_INTERSECTION: case CellRange.NO_INTERSECTION:
@ -192,10 +242,10 @@ public class HSSFConditionalFormatting
} }
} }
while( merged ); while( merged );
return cellRangeList; return cellRangeList;
} }
/** /**
* Convert a List of CellRange objects to an array of regions * Convert a List of CellRange objects to an array of regions
* *
@ -206,7 +256,7 @@ public class HSSFConditionalFormatting
{ {
int size = cellRanges.size(); int size = cellRanges.size();
Region[] regions = new Region[size]; Region[] regions = new Region[size];
for (int i = 0; i != size; i++) for (int i = 0; i != size; i++)
{ {
CellRange cr = (CellRange) cellRanges.get(i); CellRange cr = (CellRange) cellRanges.get(i);
@ -215,7 +265,7 @@ public class HSSFConditionalFormatting
} }
return regions; return regions;
} }
/** /**
* Convert array of regions to a List of CellRange objects * Convert array of regions to a List of CellRange objects
* *
@ -237,10 +287,6 @@ public class HSSFConditionalFormatting
public String toString() public String toString()
{ {
if(cfAggregate!=null) return cfAggregate.toString();
{
return cfAggregate.toString();
}
return null;
} }
} }

View File

@ -15,11 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* HSSFSheet.java
*
* Created on September 30, 2001, 3:40 PM
*/
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
@ -61,9 +56,7 @@ import java.awt.geom.AffineTransform;
* @author Jean-Pierre Paris (jean-pierre.paris at m4x dot org) (Just a little, too) * @author Jean-Pierre Paris (jean-pierre.paris at m4x dot org) (Just a little, too)
* @author Yegor Kozlov (yegor at apache.org) (Autosizing columns) * @author Yegor Kozlov (yegor at apache.org) (Autosizing columns)
*/ */
public final class HSSFSheet {
public class HSSFSheet
{
private static final int DEBUG = POILogger.DEBUG; private static final int DEBUG = POILogger.DEBUG;
/* Constants for margins */ /* Constants for margins */
@ -360,7 +353,7 @@ public class HSSFSheet
{ {
return lastrow; return lastrow;
} }
/** /**
* Creates a data validation object * Creates a data validation object
* @param obj_validation The Data validation object settings * @param obj_validation The Data validation object settings
@ -596,25 +589,25 @@ public class HSSFSheet
} }
/** /**
* Whether a record must be inserted or not at generation to indicate that * Whether a record must be inserted or not at generation to indicate that
* formula must be recalculated when workbook is opened. * formula must be recalculated when workbook is opened.
* @param value true if an uncalced record must be inserted or not at generation * @param value true if an uncalced record must be inserted or not at generation
*/ */
public void setForceFormulaRecalculation(boolean value) public void setForceFormulaRecalculation(boolean value)
{ {
sheet.setUncalced(value); sheet.setUncalced(value);
} }
/** /**
* Whether a record must be inserted or not at generation to indicate that * Whether a record must be inserted or not at generation to indicate that
* formula must be recalculated when workbook is opened. * formula must be recalculated when workbook is opened.
* @return true if an uncalced record must be inserted or not at generation * @return true if an uncalced record must be inserted or not at generation
*/ */
public boolean getForceFormulaRecalculation() public boolean getForceFormulaRecalculation()
{ {
return sheet.getUncalced(); return sheet.getUncalced();
} }
/** /**
* determines whether the output is vertically centered on the page. * determines whether the output is vertically centered on the page.
* @param value true to vertically center, false otherwise. * @param value true to vertically center, false otherwise.
@ -714,13 +707,13 @@ public class HSSFSheet
return rows.values().iterator(); return rows.values().iterator();
} }
/** /**
* Alias for {@link #rowIterator()} to allow * Alias for {@link #rowIterator()} to allow
* foreach loops * foreach loops
*/ */
public Iterator iterator() { public Iterator iterator() {
return rowIterator(); return rowIterator();
} }
/** /**
* used internally in the API to get the low level Sheet record represented by this * used internally in the API to get the low level Sheet record represented by this
@ -1001,45 +994,45 @@ public class HSSFSheet
getSheet().setMargin( margin, size ); getSheet().setMargin( margin, size );
} }
/** /**
* Answer whether protection is enabled or disabled * Answer whether protection is enabled or disabled
* @return true => protection enabled; false => protection disabled * @return true => protection enabled; false => protection disabled
*/ */
public boolean getProtect() { public boolean getProtect() {
return getSheet().isProtected()[0]; return getSheet().isProtected()[0];
} }
/** /**
* @return hashed password * @return hashed password
*/ */
public short getPassword() { public short getPassword() {
return getSheet().getPassword().getPassword(); return getSheet().getPassword().getPassword();
} }
/** /**
* Answer whether object protection is enabled or disabled * Answer whether object protection is enabled or disabled
* @return true => protection enabled; false => protection disabled * @return true => protection enabled; false => protection disabled
*/ */
public boolean getObjectProtect() { public boolean getObjectProtect() {
return getSheet().isProtected()[1]; return getSheet().isProtected()[1];
} }
/** /**
* Answer whether scenario protection is enabled or disabled * Answer whether scenario protection is enabled or disabled
* @return true => protection enabled; false => protection disabled * @return true => protection enabled; false => protection disabled
*/ */
public boolean getScenarioProtect() { public boolean getScenarioProtect() {
return getSheet().isProtected()[2]; return getSheet().isProtected()[2];
} }
/** /**
* Sets the protection on enabled or disabled * Sets the protection on enabled or disabled
* @param protect true => protection enabled; false => protection disabled * @param protect true => protection enabled; false => protection disabled
* @deprecated use protectSheet(String, boolean, boolean) * @deprecated use protectSheet(String, boolean, boolean)
*/ */
public void setProtect(boolean protect) { public void setProtect(boolean protect) {
getSheet().getProtect().setProtect(protect); getSheet().getProtect().setProtect(protect);
} }
/** /**
* Sets the protection enabled as well as the password * Sets the protection enabled as well as the password
@ -1069,29 +1062,29 @@ public class HSSFSheet
sclRecord.setDenominator((short)denominator); sclRecord.setDenominator((short)denominator);
getSheet().setSCLRecord(sclRecord); getSheet().setSCLRecord(sclRecord);
} }
/** /**
* The top row in the visible view when the sheet is * The top row in the visible view when the sheet is
* first viewed after opening it in a viewer * first viewed after opening it in a viewer
* @return short indicating the rownum (0 based) of the top row * @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 * The left col in the visible view when the sheet is
* first viewed after opening it in a viewer * first viewed after opening it in a viewer
* @return short indicating the rownum (0 based) of the top row * @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. * file is first opened in a viewer.
* @param toprow the top row to show in desktop window pane * @param toprow the top row to show in desktop window pane
* @param leftcol the left column 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); this.sheet.setLeftCol((short)leftcol);
} }
/** /**
* Shifts the merged regions left or right depending on mode * Shifts the merged regions left or right depending on mode
* <p> * <p>
* TODO: MODE , this is only row specific * TODO: MODE , this is only row specific
* @param startRow * @param startRow
* @param endRow * @param endRow
* @param n * @param n
* @param isRow * @param isRow
*/ */
protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) { protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
List shiftedRegions = new ArrayList(); List shiftedRegions = new ArrayList();
//move merged regions completely if they fall within the new region boundaries when they are shifted //move merged regions completely if they fall within the new region boundaries when they are shifted
for (int i = 0; i < this.getNumMergedRegions(); i++) { for (int i = 0; i < this.getNumMergedRegions(); i++) {
Region merged = this.getMergedRegionAt(i); Region merged = this.getMergedRegionAt(i);
boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow); boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow); boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
//dont check if it's not within the shifted area //dont check if it's not within the shifted area
if (! (inStart && inEnd)) continue; if (! (inStart && inEnd)) continue;
//only shift if the region outside the shifted rows is not merged too //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)){ if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
merged.setRowFrom(merged.getRowFrom()+n); merged.setRowFrom(merged.getRowFrom()+n);
merged.setRowTo(merged.getRowTo()+n); merged.setRowTo(merged.getRowTo()+n);
//have to remove/add it back //have to remove/add it back
shiftedRegions.add(merged); shiftedRegions.add(merged);
this.removeMergedRegion(i); this.removeMergedRegion(i);
i = i -1; // we have to back up now since we removed one i = i -1; // we have to back up now since we removed one
} }
} }
//readd so it doesn't get shifted again //readd so it doesn't get shifted again
Iterator iterator = shiftedRegions.iterator(); Iterator iterator = shiftedRegions.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Region region = (Region)iterator.next(); Region region = (Region)iterator.next();
this.addMergedRegion(region); this.addMergedRegion(region);
} }
} }
/** /**
* Shifts rows between startRow and endRow n number of rows. * 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 * @param n the number of rows to shift
*/ */
public void shiftRows( int startRow, int endRow, int n ) { 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); shiftMerged(startRow, endRow, n, true);
sheet.shiftRowBreaks(startRow, endRow, n); sheet.shiftRowBreaks(startRow, endRow, n);
for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc ) for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc )
{ {
HSSFRow row = getRow( rowNum ); 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++ ) for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ )
{ {
cell = row2Replace.getCell( col ); cell = row2Replace.getCell( col );
if ( cell != null ) if ( cell != null )
row2Replace.removeCell( cell ); row2Replace.removeCell( cell );
} }
if (row == null) continue; // Nothing to do for this row if (row == null) continue; // Nothing to do for this row
else { else {
if (copyRowHeight) { if (copyRowHeight) {
row2Replace.setHeight(row.getHeight()); row2Replace.setHeight(row.getHeight());
} }
if (resetOriginalRowHeight) { if (resetOriginalRowHeight) {
row.setHeight((short)0xff); row.setHeight((short)0xff);
} }
} }
for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ ) for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ )
{ {
cell = row.getCell( 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 ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 );
if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 ); if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 );
// Update any formulas on this sheet that point to // Update any formulas on this sheet that point to
// rows which have been moved // rows which have been moved
updateFormulasAfterShift(startRow, endRow, n); updateFormulasAfterShift(startRow, endRow, n);
} }
/** /**
* Called by shiftRows to update formulas on this sheet * Called by shiftRows to update formulas on this sheet
* to point to the new location of moved rows * to point to the new location of moved rows
*/ */
private void updateFormulasAfterShift(int startRow, int endRow, int n) { private void updateFormulasAfterShift(int startRow, int endRow, int n) {
// Need to look at every cell on the sheet // Need to look at every cell on the sheet
// Not just those that were moved // Not just those that were moved
Iterator ri = rowIterator(); Iterator ri = rowIterator();
while(ri.hasNext()) { while(ri.hasNext()) {
HSSFRow r = (HSSFRow)ri.next(); HSSFRow r = (HSSFRow)ri.next();
Iterator ci = r.cellIterator(); Iterator ci = r.cellIterator();
while(ci.hasNext()) { while(ci.hasNext()) {
HSSFCell c = (HSSFCell)ci.next(); HSSFCell c = (HSSFCell)ci.next();
if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
// Since it's a formula cell, process the // Since it's a formula cell, process the
// formula string, and look to see if // formula string, and look to see if
// it contains any references // it contains any references
FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook()); FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook());
fp.parse(); fp.parse();
// Look for references, and update if needed // Look for references, and update if needed
Ptg[] ptgs = fp.getRPNPtg(); Ptg[] ptgs = fp.getRPNPtg();
boolean changed = false; boolean changed = false;
for(int i=0; i<ptgs.length; i++) { for(int i=0; i<ptgs.length; i++) {
if(ptgs[i] instanceof ReferencePtg) { if(ptgs[i] instanceof ReferencePtg) {
ReferencePtg rptg = (ReferencePtg)ptgs[i]; ReferencePtg rptg = (ReferencePtg)ptgs[i];
if(startRow <= rptg.getRowAsInt() && if(startRow <= rptg.getRowAsInt() &&
rptg.getRowAsInt() <= endRow) { rptg.getRowAsInt() <= endRow) {
// References a row that moved // References a row that moved
rptg.setRow(rptg.getRowAsInt() + n); rptg.setRow(rptg.getRowAsInt() + n);
changed = true; changed = true;
} }
} }
} }
// If any references were changed, then // If any references were changed, then
// re-create the formula string // re-create the formula string
if(changed) { if(changed) {
c.setCellFormula( c.setCellFormula(
fp.toFormulaString(ptgs) fp.toFormulaString(ptgs)
); );
} }
} }
} }
} }
} }
@ -1349,7 +1342,7 @@ public class HSSFSheet
{ {
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane ); getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
} }
/** /**
* Returns the information regarding the currently configured pane (split or freeze). * Returns the information regarding the currently configured pane (split or freeze).
* @return null if no pane configured, or the pane information. * @return null if no pane configured, or the pane information.
@ -1371,7 +1364,7 @@ public class HSSFSheet
* @return whether gridlines are displayed * @return whether gridlines are displayed
*/ */
public boolean isDisplayGridlines() { public boolean isDisplayGridlines() {
return sheet.isDisplayGridlines(); return sheet.isDisplayGridlines();
} }
/** /**
@ -1387,7 +1380,7 @@ public class HSSFSheet
* @return whether formulas are displayed * @return whether formulas are displayed
*/ */
public boolean isDisplayFormulas() { public boolean isDisplayFormulas() {
return sheet.isDisplayFormulas(); return sheet.isDisplayFormulas();
} }
/** /**
@ -1403,16 +1396,16 @@ public class HSSFSheet
* @return whether RowColHeadings are displayed * @return whether RowColHeadings are displayed
*/ */
public boolean isDisplayRowColHeadings() { public boolean isDisplayRowColHeadings() {
return sheet.isDisplayRowColHeadings(); return sheet.isDisplayRowColHeadings();
} }
/** /**
* Sets a page break at the indicated row * Sets a page break at the indicated row
* @param row FIXME: Document this! * @param row FIXME: Document this!
*/ */
public void setRowBreak(int row) { public void setRowBreak(int row) {
validateRow(row); validateRow(row);
sheet.setRowBreak(row, (short)0, (short)255); sheet.setRowBreak(row, (short)0, (short)255);
} }
/** /**
@ -1421,35 +1414,35 @@ public class HSSFSheet
* @return FIXME: Document this! * @return FIXME: Document this!
*/ */
public boolean isRowBroken(int row) { public boolean isRowBroken(int row) {
return sheet.isRowBroken(row); return sheet.isRowBroken(row);
} }
/** /**
* Removes the page break at the indicated row * Removes the page break at the indicated row
* @param row * @param row
*/ */
public void removeRowBreak(int row) { public void removeRowBreak(int row) {
sheet.removeRowBreak(row); sheet.removeRowBreak(row);
} }
/** /**
* Retrieves all the horizontal page breaks * Retrieves all the horizontal page breaks
* @return all the horizontal page breaks, or null if there are no row page breaks * @return all the horizontal page breaks, or null if there are no row page breaks
*/ */
public int[] getRowBreaks(){ public int[] getRowBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumRowBreaks(); int count = sheet.getNumRowBreaks();
if (count > 0) { if (count > 0) {
int[] returnValue = new int[count]; int[] returnValue = new int[count];
Iterator iterator = sheet.getRowBreaks(); Iterator iterator = sheet.getRowBreaks();
int i = 0; int i = 0;
while (iterator.hasNext()) { while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = (int)breakItem.main; returnValue[i++] = (int)breakItem.main;
} }
return returnValue; return returnValue;
} }
return null; return null;
} }
/** /**
@ -1457,29 +1450,29 @@ public class HSSFSheet
* @return all the vertical page breaks, or null if there are no column page breaks * @return all the vertical page breaks, or null if there are no column page breaks
*/ */
public short[] getColumnBreaks(){ public short[] getColumnBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumColumnBreaks(); int count = sheet.getNumColumnBreaks();
if (count > 0) { if (count > 0) {
short[] returnValue = new short[count]; short[] returnValue = new short[count];
Iterator iterator = sheet.getColumnBreaks(); Iterator iterator = sheet.getColumnBreaks();
int i = 0; int i = 0;
while (iterator.hasNext()) { while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = breakItem.main; returnValue[i++] = breakItem.main;
} }
return returnValue; return returnValue;
} }
return null; return null;
} }
/** /**
* Sets a page break at the indicated column * Sets a page break at the indicated column
* @param column * @param column
*/ */
public void setColumnBreak(short column) { public void setColumnBreak(short column) {
validateColumn(column); validateColumn(column);
sheet.setColumnBreak(column, (short)0, (short)65535); sheet.setColumnBreak(column, (short)0, (short)65535);
} }
/** /**
@ -1488,33 +1481,33 @@ public class HSSFSheet
* @return FIXME: Document this! * @return FIXME: Document this!
*/ */
public boolean isColumnBroken(short column) { public boolean isColumnBroken(short column) {
return sheet.isColumnBroken(column); return sheet.isColumnBroken(column);
} }
/** /**
* Removes a page break at the indicated column * Removes a page break at the indicated column
* @param column * @param column
*/ */
public void removeColumnBreak(short column) { public void removeColumnBreak(short column) {
sheet.removeColumnBreak(column); sheet.removeColumnBreak(column);
} }
/** /**
* Runs a bounds check for row numbers * Runs a bounds check for row numbers
* @param row * @param row
*/ */
protected void validateRow(int row) { protected void validateRow(int row) {
if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535"); if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535");
if (row < 0) throw new IllegalArgumentException("Minumum row number is 0"); if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
} }
/** /**
* Runs a bounds check for column numbers * Runs a bounds check for column numbers
* @param column * @param column
*/ */
protected void validateColumn(short column) { protected void validateColumn(short column) {
if (column > 255) throw new IllegalArgumentException("Maximum column number is 255"); if (column > 255) throw new IllegalArgumentException("Maximum column number is 255");
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0"); if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
} }
/** /**
@ -1559,7 +1552,7 @@ public class HSSFSheet
agg.setPatriarch(patriarch); agg.setPatriarch(patriarch);
return patriarch; return patriarch;
} }
/** /**
* Returns the top-level drawing patriach, if there is * Returns the top-level drawing patriach, if there is
* one. * one.
@ -1573,32 +1566,32 @@ public class HSSFSheet
* start from scratch! * start from scratch!
*/ */
public HSSFPatriarch getDrawingPatriarch() { public HSSFPatriarch getDrawingPatriarch() {
book.findDrawingGroup(); book.findDrawingGroup();
// If there's now no drawing manager, then there's // If there's now no drawing manager, then there's
// no drawing escher records on the workbook // no drawing escher records on the workbook
if(book.getDrawingManager() == null) { if(book.getDrawingManager() == null) {
return null; return null;
} }
int found = sheet.aggregateDrawingRecords( int found = sheet.aggregateDrawingRecords(
book.getDrawingManager(), false book.getDrawingManager(), false
); );
if(found == -1) { if(found == -1) {
// Workbook has drawing stuff, but this sheet doesn't // Workbook has drawing stuff, but this sheet doesn't
return null; return null;
} }
// Grab our aggregate record, and wire it up // Grab our aggregate record, and wire it up
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid); EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
HSSFPatriarch patriarch = new HSSFPatriarch(this, agg); HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
agg.setPatriarch(patriarch); agg.setPatriarch(patriarch);
// Have it process the records into high level objects // Have it process the records into high level objects
// as best it can do (this step may eat anything // as best it can do (this step may eat anything
// that isn't supported, you were warned...) // that isn't supported, you were warned...)
agg.convertRecordsToUserModel(); agg.convertRecordsToUserModel();
// Return what we could cope with // Return what we could cope with
return patriarch; return patriarch;
} }
@ -1652,7 +1645,7 @@ public class HSSFSheet
* @param style the style to set * @param style the style to set
*/ */
public void setDefaultColumnStyle(short column, HSSFCellStyle style) { 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. * '0' looks to be a good choice.
*/ */
char defaultChar = '0'; char defaultChar = '0';
/** /**
* This is the multiple that the font height is scaled by when determining the * This is the multiple that the font height is scaled by when determining the
* boundary of rotated text. * boundary of rotated text.
*/ */
double fontHeightMultiple = 2.0; double fontHeightMultiple = 2.0;
FontRenderContext frc = new FontRenderContext(null, true, true); FontRenderContext frc = new FontRenderContext(null, true, true);
HSSFWorkbook wb = new HSSFWorkbook(book); HSSFWorkbook wb = new HSSFWorkbook(book);
@ -1800,7 +1793,7 @@ public class HSSFSheet
/** /**
* Copy text attributes from the supplied HSSFFont to Java2D AttributedString * 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.FAMILY, font.getFontName(), startIdx, endIdx);
str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints())); str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints()));
if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx); 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 * A factory method allowing to create a conditional formatting rule
* with a cell comparison operator and * with a cell comparison operator and
* formatting rules such as font format, border format and pattern format * formatting rules such as font format, border format and pattern format
* *
* @param comparisonOperation - one of the following values: <p> * @param comparisonOperation - one of the following values: <p>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* </p> * </p>
* @param formula1 - formula for the valued, compared with the cell * @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_BETWEEN}) and
* {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
* @param fontFmt - font formatting rules * @param fontFmt - font formatting rules
* @param bordFmt - border formatting rules * @param bordFmt - border formatting rules
* @param patternFmt - pattern formatting rules * @param patternFmt - pattern formatting rules
* @return * @return
* *
*/ */
public HSSFConditionalFormattingRule createConditionalFormattingRule( public HSSFConditionalFormattingRule createConditionalFormattingRule(
byte comparisonOperation, byte comparisonOperation,
String formula1, String formula1,
String formula2, String formula2,
HSSFFontFormatting fontFmt, HSSFFontFormatting fontFmt,
HSSFBorderFormatting bordFmt, HSSFBorderFormatting bordFmt,
HSSFPatternFormatting patternFmt) HSSFPatternFormatting patternFmt)
{ {
HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
cf.setFontFormatting(fontFmt); cf.setFontFormatting(fontFmt);
cf.setBorderFormatting(bordFmt); cf.setBorderFormatting(bordFmt);
cf.setPatternFormatting(patternFmt); cf.setPatternFormatting(patternFmt);
cf.setCellComparisonCondition(comparisonOperation, formula1, formula2); cf.setCellComparisonCondition(comparisonOperation, formula1, formula2);
return cf; 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. <br> * and formatting rules such as font format, border format and pattern format. <br>
* *
* 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: <p> * @param comparisonOperation - one of the following values: <p>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li> * <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* </p> * </p>
* @param formula1 - formula for the valued, compared with the cell * @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_BETWEEN}) and
* {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations) * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
* @param fontFmt - font formatting rules * @param fontFmt - font formatting rules
* @param bordFmt - border formatting rules * @param bordFmt - border formatting rules
* @param patternFmt - pattern formatting rules * @param patternFmt - pattern formatting rules
* @return * @return
* *
*/ */
public HSSFConditionalFormattingRule createConditionalFormattingRule( public HSSFConditionalFormattingRule createConditionalFormattingRule(
String formula, String formula,
HSSFFontFormatting fontFmt, HSSFFontFormatting fontFmt,
HSSFBorderFormatting bordFmt, HSSFBorderFormatting bordFmt,
HSSFPatternFormatting patternFmt) HSSFPatternFormatting patternFmt)
{ {
HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook); HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
cf.setFontFormatting(fontFmt); cf.setFontFormatting(fontFmt);
cf.setBorderFormatting(bordFmt); cf.setBorderFormatting(bordFmt);
cf.setPatternFormatting(patternFmt); cf.setPatternFormatting(patternFmt);
cf.setFormulaCondition(formula); cf.setFormulaCondition(formula);
return cf; return cf;
} }
/** /**
* Adds a copy of HSSFConditionalFormatting object to the sheet * Adds a copy of HSSFConditionalFormatting object to the sheet
* <p>This method could be used to copy HSSFConditionalFormatting object * <p>This method could be used to copy HSSFConditionalFormatting object
@ -1920,72 +1913,71 @@ public class HSSFSheet
* <pre> * <pre>
* HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index); * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
* newSheet.addConditionalFormatting(cf); * newSheet.addConditionalFormatting(cf);
* </pre> * </pre>
* *
* @param cf HSSFConditionalFormatting object * @param cf HSSFConditionalFormatting object
* @return index of the new Conditional Formatting object * @return index of the new Conditional Formatting object
*/ */
public int addConditionalFormatting( HSSFConditionalFormatting cf ) public int addConditionalFormatting( HSSFConditionalFormatting cf )
{ {
HSSFConditionalFormatting cfClone = new HSSFConditionalFormatting(this,cf.cfAggregate.cloneCFAggregate()); CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
cfClone.sheet=this;
return sheet.addConditionalFormatting(cfClone.cfAggregate); return sheet.addConditionalFormatting(cfraClone);
} }
/** /**
* Allows to add a new Conditional Formatting set to the sheet. * 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 * @param cfRules - set of up to three conditional formatting rules
* *
* @return index of the newly created Conditional Formatting object * @return index of the newly created Conditional Formatting object
*/ */
public int addConditionalFormatting( Region [] regions, HSSFConditionalFormattingRule [] cfRules ) public int addConditionalFormatting( Region [] regions, HSSFConditionalFormattingRule [] cfRules )
{ {
HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this); HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this);
cf.setFormattingRegions(regions); cf.setFormattingRegions(regions);
if( cfRules != null ) if( cfRules != null )
{ {
for( int i=0; i!= cfRules.length; i++ ) for( int i=0; i!= cfRules.length; i++ )
{ {
cf.addConditionalFormat(cfRules[i]); cf.addRule(cfRules[i]);
} }
} }
return sheet.addConditionalFormatting(cf.cfAggregate); 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 * gets Conditional Formatting object at a particular index
*/ * @param index of the Conditional Formatting object to fetch
public int getNumConditionalFormattings() * @return Conditional Formatting object
{ */
return sheet.getNumConditionalFormattings();
}
/** public HSSFConditionalFormatting getConditionalFormattingAt(int index)
* removes a Conditional Formatting object by index {
* @param index of a Conditional Formatting object to remove CFRecordsAggregate cf = sheet.getCFRecordsAggregateAt(index);
*/ if( cf != null )
public void removeConditionalFormatting(int index) {
{ return new HSSFConditionalFormatting(this,cf);
sheet.removeConditionalFormatting(index); }
} 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);
}
} }