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 80b0f9f6b8
commit 844d1de676
3 changed files with 509 additions and 474 deletions

View File

@ -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;
public final static short sid = -2008; // not a real BIFF record
private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
private CFHeaderRecord header;
private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
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 (log.check(POILogger.DEBUG))
@ -93,66 +94,66 @@ public class CFRecordsAggregate extends Record
cfRecords.header.setNumberOfConditionalFormats(nRules);
}
}
return cfRecords;
}
/**
* Create a deep clone of the record
* @return
*/
public CFRecordsAggregate cloneCFAggregate()
{
ArrayList records = new ArrayList(this.rules.size()+1);
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);
}
/** You never fill an aggregate */
}
return cfRecords;
}
/**
* Create a deep clone of the record
* @return
*/
public CFRecordsAggregate cloneCFAggregate()
{
ArrayList records = new ArrayList(this.rules.size()+1);
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);
}
/** You never fill an aggregate */
protected void fillFields(RecordInputStream in)
{
}
public short getSid()
{
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)
{
// 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<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;
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 <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
@ -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<cellRangeList.size(); i++)
@ -149,7 +199,7 @@ public class HSSFConditionalFormatting
for( int j=i+1; j<cellRangeList.size(); j++)
{
CellRange range2 = (CellRange)cellRangeList.get(j);
switch(range1.intersect(range2))
{
case CellRange.NO_INTERSECTION:
@ -192,10 +242,10 @@ public class HSSFConditionalFormatting
}
}
while( merged );
return cellRangeList;
}
/**
* Convert a List of CellRange objects to an array of regions
*
@ -206,7 +256,7 @@ public class HSSFConditionalFormatting
{
int size = cellRanges.size();
Region[] regions = new Region[size];
for (int i = 0; i != size; i++)
{
CellRange cr = (CellRange) cellRanges.get(i);
@ -215,7 +265,7 @@ public class HSSFConditionalFormatting
}
return regions;
}
/**
* Convert array of regions to a List of CellRange objects
*
@ -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 */
@ -360,7 +353,7 @@ public class HSSFSheet
{
return lastrow;
}
/**
* Creates a data validation object
* @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.
* @param value true if an uncalced record must be inserted or not at generation
*/
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.
* @return true if an uncalced record must be inserted or not at generation
*/
public boolean getForceFormulaRecalculation()
{
return sheet.getUncalced();
return sheet.getUncalced();
}
/**
* determines whether the output is vertically centered on the page.
* @param value true to vertically center, false otherwise.
@ -714,13 +707,13 @@ public class HSSFSheet
return rows.values().iterator();
}
/**
* Alias for {@link #rowIterator()} to allow
* Alias for {@link #rowIterator()} to allow
* foreach loops
*/
public Iterator iterator() {
return rowIterator();
}
/**
* 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 );
}
/**
* 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
@ -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
* <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);
}
/**
@ -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 (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 );
@ -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<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)
);
}
}
}
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)
);
}
}
}
}
}
@ -1349,7 +1342,7 @@ public class HSSFSheet
{
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
}
/**
* Returns the information regarding the currently configured pane (split or freeze).
* @return null if no pane configured, or the pane information.
@ -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,16 +1396,16 @@ public class HSSFSheet
* @return whether RowColHeadings are displayed
*/
public boolean isDisplayRowColHeadings() {
return sheet.isDisplayRowColHeadings();
return sheet.isDisplayRowColHeadings();
}
/**
* Sets a page break at the indicated row
* @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,35 +1414,35 @@ public class HSSFSheet
* @return FIXME: Document this!
*/
public boolean isRowBroken(int row) {
return sheet.isRowBroken(row);
return sheet.isRowBroken(row);
}
/**
* Removes the page break at the indicated row
* @param row
*/
public void removeRowBreak(int row) {
sheet.removeRowBreak(row);
sheet.removeRowBreak(row);
}
/**
* Retrieves all the horizontal page breaks
* @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,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: <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>
* </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>
* </p>
* @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. <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>
* <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>
* <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
* @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
* <p>This method could be used to copy HSSFConditionalFormatting object
@ -1920,72 +1913,71 @@ public class HSSFSheet
* <pre>
* HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
* newSheet.addConditionalFormatting(cf);
* </pre>
*
* </pre>
*
* @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();
}
/**
* gets Conditional Formatting object at a particular index
* @param index of the Conditional Formatting object to fetch
* @return Conditional Formatting object
*/
/**
* removes a Conditional Formatting object by index
* @param index of a Conditional Formatting object to remove
*/
public void removeConditionalFormatting(int index)
{
sheet.removeConditionalFormatting(index);
}
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);
}
}