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,53 +35,54 @@ 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;
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 List rules;
// List of CFRuleRecord objects
private final List rules;
public CFRecordsAggregate()
{
header = null;
rules = new ArrayList(3);
}
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);
/**
* 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 count = 0;
Record rec = ( Record ) recs.get(offset++);
int offset = pOffset;
CFRecordsAggregate cfRecords = new CFRecordsAggregate();
ArrayList records = new ArrayList(4);
if (rec.getSid() == CFHeaderRecord.sid)
{
records.add(rec);
cfRecords.header = (CFHeaderRecord)rec;
Record rec = ( Record ) recs.get(offset++);
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 (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())
{
@ -93,30 +94,30 @@ public class CFRecordsAggregate extends Record
cfRecords.header.setNumberOfConditionalFormats(nRules);
}
}
return cfRecords;
}
}
return cfRecords;
}
/**
* Create a deep clone of the record
* @return
*/
public CFRecordsAggregate cloneCFAggregate()
{
/**
* Create a deep clone of the record
* @return
*/
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++)
{
Record rec = (Record)((Record)this.rules.get(i)).clone();
records.add(rec);
}
return createCFAggregate(records, 0);
}
for (int i=0; i<this.rules.size();i++)
{
Record rec = (Record)((Record)this.rules.get(i)).clone();
records.add(rec);
}
return createCFAggregate(records, 0);
}
/** You never fill an aggregate */
/** You never fill an aggregate */
protected void fillFields(RecordInputStream in)
{
}
@ -126,31 +127,31 @@ public class CFRecordsAggregate extends Record
return sid;
}
/**
* called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a
* byte array.
*
* @param offset to begin writing at
* @param data byte array containing instance data
* @return number of bytes written
*/
/**
* called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a
* byte array.
*
* @param offset to begin writing at
* @param data byte array containing instance data
* @return number of bytes written
*/
public int serialize(int offset, byte[] data)
{
int pos = offset;
int pos = offset;
if( header != null && rules.size()>0 )
{
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)
@ -179,20 +180,20 @@ 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<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);
if(cfRule!=null)
{
buffer.append(cfRule.toString());
}
buffer.append(cfRule.toString());
}
}
buffer.append("[/CF]\n");
return buffer.toString();
}
}

View File

@ -27,8 +27,14 @@ import org.apache.poi.hssf.util.Region;
/**
* 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:
* <PRE>
@ -36,7 +42,15 @@ import org.apache.poi.hssf.util.Region;
* newSheet.addConditionalFormatting(cf);
* </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:
*
* <PRE>
* // 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;
private final HSSFSheet sheet;
private final CFRecordsAggregate cfAggregate;
protected HSSFConditionalFormatting(HSSFSheet sheet)
{
this.sheet = sheet;
this.cfAggregate = new CFRecordsAggregate();
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 <tt>Region</tt>s. never <code>null</code>
*/
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:<br>
* <li>if a cell range is completely inside of another cell range, it gets removed from the list
@ -237,10 +287,6 @@ public class HSSFConditionalFormatting
public String toString()
{
if(cfAggregate!=null)
{
return cfAggregate.toString();
}
return null;
return cfAggregate.toString();
}
}

View File

@ -15,11 +15,6 @@
limitations under the License.
==================================================================== */
/*
* HSSFSheet.java
*
* Created on September 30, 2001, 3:40 PM
*/
package org.apache.poi.hssf.usermodel;
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 Yegor Kozlov (yegor at apache.org) (Autosizing columns)
*/
public class HSSFSheet
{
public final class HSSFSheet {
private static final int DEBUG = POILogger.DEBUG;
/* Constants for margins */
@ -602,7 +595,7 @@ public class HSSFSheet
*/
public void setForceFormulaRecalculation(boolean value)
{
sheet.setUncalced(value);
sheet.setUncalced(value);
}
/**
* Whether a record must be inserted or not at generation to indicate that
@ -611,7 +604,7 @@ public class HSSFSheet
*/
public boolean getForceFormulaRecalculation()
{
return sheet.getUncalced();
return sheet.getUncalced();
}
@ -1001,45 +994,45 @@ public class HSSFSheet
getSheet().setMargin( margin, size );
}
/**
* Answer whether protection is enabled or disabled
* @return true => protection enabled; false => protection disabled
*/
public boolean getProtect() {
return getSheet().isProtected()[0];
}
/**
* 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();
}
/**
* @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 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];
}
/**
* 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
/**
* 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
@ -1077,7 +1070,7 @@ public class HSSFSheet
*/
public short getTopRow()
{
return sheet.getTopRow();
return sheet.getTopRow();
}
/**
@ -1087,7 +1080,7 @@ public class HSSFSheet
*/
public short getLeftCol()
{
return sheet.getLeftCol();
return sheet.getLeftCol();
}
/**
@ -1101,49 +1094,49 @@ public class HSSFSheet
this.sheet.setLeftCol((short)leftcol);
}
/**
* Shifts the merged regions left or right depending on mode
* <p>
* 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);
/**
* Shifts the merged regions left or right depending on mode
* <p>
* 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);
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;
//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
//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);
}
/**
@ -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 (row == null) continue; // Nothing to do for this row
else {
if (copyRowHeight) {
row2Replace.setHeight(row.getHeight());
}
if (resetOriginalRowHeight) {
row.setHeight((short)0xff);
}
}
if (resetOriginalRowHeight) {
row.setHeight((short)0xff);
}
}
for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ )
{
cell = row.getCell( col );
@ -1259,44 +1252,44 @@ public class HSSFSheet
* 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();
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<ptgs.length; i++) {
if(ptgs[i] instanceof ReferencePtg) {
ReferencePtg rptg = (ReferencePtg)ptgs[i];
if(startRow <= rptg.getRowAsInt() &&
rptg.getRowAsInt() <= endRow) {
// References a row that moved
rptg.setRow(rptg.getRowAsInt() + n);
changed = true;
}
}
}
// If any references were changed, then
// re-create the formula string
if(changed) {
c.setCellFormula(
fp.toFormulaString(ptgs)
);
}
}
}
// Look for references, and update if needed
Ptg[] ptgs = fp.getRPNPtg();
boolean changed = false;
for(int i=0; i<ptgs.length; i++) {
if(ptgs[i] instanceof ReferencePtg) {
ReferencePtg rptg = (ReferencePtg)ptgs[i];
if(startRow <= rptg.getRowAsInt() &&
rptg.getRowAsInt() <= endRow) {
// References a row that moved
rptg.setRow(rptg.getRowAsInt() + n);
changed = true;
}
}
}
// If any references were changed, then
// re-create the formula string
if(changed) {
c.setCellFormula(
fp.toFormulaString(ptgs)
);
}
}
}
}
}
@ -1371,7 +1364,7 @@ public class HSSFSheet
* @return whether gridlines are displayed
*/
public boolean isDisplayGridlines() {
return sheet.isDisplayGridlines();
return sheet.isDisplayGridlines();
}
/**
@ -1387,7 +1380,7 @@ public class HSSFSheet
* @return whether formulas are displayed
*/
public boolean isDisplayFormulas() {
return sheet.isDisplayFormulas();
return sheet.isDisplayFormulas();
}
/**
@ -1403,7 +1396,7 @@ public class HSSFSheet
* @return whether RowColHeadings are displayed
*/
public boolean isDisplayRowColHeadings() {
return sheet.isDisplayRowColHeadings();
return sheet.isDisplayRowColHeadings();
}
/**
@ -1411,8 +1404,8 @@ public class HSSFSheet
* @param row FIXME: Document this!
*/
public void setRowBreak(int row) {
validateRow(row);
sheet.setRowBreak(row, (short)0, (short)255);
validateRow(row);
sheet.setRowBreak(row, (short)0, (short)255);
}
/**
@ -1421,7 +1414,7 @@ public class HSSFSheet
* @return FIXME: Document this!
*/
public boolean isRowBroken(int row) {
return sheet.isRowBroken(row);
return sheet.isRowBroken(row);
}
/**
@ -1429,7 +1422,7 @@ public class HSSFSheet
* @param row
*/
public void removeRowBreak(int row) {
sheet.removeRowBreak(row);
sheet.removeRowBreak(row);
}
/**
@ -1437,19 +1430,19 @@ public class HSSFSheet
* @return all the horizontal page breaks, or null if there are no row page breaks
*/
public int[] getRowBreaks(){
//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;
//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,19 +1450,19 @@ 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;
}
@ -1478,8 +1471,8 @@ public class HSSFSheet
* @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,7 +1481,7 @@ public class HSSFSheet
* @return FIXME: Document this!
*/
public boolean isColumnBroken(short column) {
return sheet.isColumnBroken(column);
return sheet.isColumnBroken(column);
}
/**
@ -1496,7 +1489,7 @@ public class HSSFSheet
* @param column
*/
public void removeColumnBreak(short column) {
sheet.removeColumnBreak(column);
sheet.removeColumnBreak(column);
}
/**
@ -1504,8 +1497,8 @@ public class HSSFSheet
* @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");
}
/**
@ -1513,8 +1506,8 @@ public class HSSFSheet
* @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");
}
/**
@ -1573,23 +1566,23 @@ public class HSSFSheet
* start from scratch!
*/
public HSSFPatriarch getDrawingPatriarch() {
book.findDrawingGroup();
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;
}
// 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;
}
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
// Grab our aggregate record, and wire it up
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
agg.setPatriarch(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);
}
/**
@ -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);
@ -1838,14 +1831,14 @@ public class HSSFSheet
* formatting rules such as font format, border format and pattern format
*
* @param comparisonOperation - one of the following values: <p>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* </p>
* @param formula1 - formula for the valued, compared with the cell
* @param formula2 - second formula (only used with
@ -1858,19 +1851,19 @@ public class HSSFSheet
*
*/
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;
}
/**
@ -1880,14 +1873,14 @@ public class HSSFSheet
* 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>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
* <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
* </p>
* @param formula1 - formula for the valued, compared with the cell
* @param formula2 - second formula (only used with
@ -1900,17 +1893,17 @@ public class HSSFSheet
*
*/
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;
}
/**
@ -1927,9 +1920,9 @@ public class HSSFSheet
*/
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);
}
/**
@ -1943,49 +1936,48 @@ public class HSSFSheet
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
*/
/**
* 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;
}
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);
}
/**
* @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);
}
}