-
/* ====================================================================
* The Apache Software License, Version 1.1
*
*/
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.util.POILogFactory;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.VCenterRecord;
+import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.util.Region;
+import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import java.util.Iterator;
* High level representation of a worksheet.
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
- * @version 1.0-pre
+ * @author Libin Roman (romal at vistaportal.com)
*/
public class HSSFSheet
{
- private static final int DEBUG = POILogger.DEBUG;
+ private static final int DEBUG = POILogger.DEBUG;
/**
* Used for compile-time optimization. This is the initial size for the collection of
* by setting this to a higher number and recompiling a custom edition of HSSFSheet.
*/
- public final static int INITIAL_CAPACITY = 20;
+ public final static int INITIAL_CAPACITY = 20;
/**
* reference to the low level Sheet object
*/
- private Sheet sheet;
- private TreeMap rows;
- private Workbook book;
- private int firstrow;
- private int lastrow;
+ private Sheet sheet;
+ private TreeMap rows;
+ private Workbook book;
+ private int firstrow;
+ private int lastrow;
private static POILogger log = POILogFactory.getLogger(HSSFSheet.class);
/**
protected HSSFSheet(Workbook book)
{
- sheet = Sheet.createSheet();
- rows = new TreeMap(); // new ArrayList(INITIAL_CAPACITY);
+ sheet = Sheet.createSheet();
+ rows = new TreeMap(); // new ArrayList(INITIAL_CAPACITY);
this.book = book;
}
protected HSSFSheet(Workbook book, Sheet sheet)
{
this.sheet = sheet;
- rows = new TreeMap();
- this.book = book;
+ rows = new TreeMap();
+ this.book = book;
setPropertiesFromSheet(sheet);
}
- /** private default constructor prevents bogus initializationless construction */
-
- private HSSFSheet()
- {
- }
/**
* used internally to set the properties given a Sheet object
private void setPropertiesFromSheet(Sheet sheet)
{
- int sloc = sheet.getLoc();
- RowRecord row = sheet.getNextRow();
+ int sloc = sheet.getLoc();
+ RowRecord row = sheet.getNextRow();
while (row != null)
{
row = sheet.getNextRow();
}
sheet.setLoc(sloc);
- CellValueRecordInterface cval = sheet.getNextValueRecord();
- long timestart = System.currentTimeMillis();
+ CellValueRecordInterface cval = sheet.getNextValueRecord();
+ long timestart = System.currentTimeMillis();
log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ",
new Long(timestart));
while (cval != null)
{
- long cellstart = System.currentTimeMillis();
- HSSFRow hrow = lastrow;
+ long cellstart = System.currentTimeMillis();
+ HSSFRow hrow = lastrow;
if ((lastrow == null) || (lastrow.getRowNum() != cval.getRow()))
{
while (iter.hasNext())
{
- HSSFCell cell = ( HSSFCell ) iter.next();
+ HSSFCell cell = (HSSFCell) iter.next();
sheet.removeValueRecord(row.getRowNum(),
- cell.getCellValueRecord());
+ cell.getCellValueRecord());
}
sheet.removeRow(row.getRowRecord());
}
private int findLastRow(int lastrow)
{
- int rownum = lastrow - 1;
- HSSFRow r = getRow(rownum);
+ int rownum = lastrow - 1;
+ HSSFRow r = getRow(rownum);
- while (r == null)
+ while (r == null && rownum >= 0)
{
r = getRow(--rownum);
}
private int findFirstRow(int firstrow)
{
- int rownum = firstrow + 1;
- HSSFRow r = getRow(rownum);
+ int rownum = firstrow + 1;
+ HSSFRow r = getRow(rownum);
- while (r == null)
+ while (r == null && rownum <= getLastRowNum())
{
r = getRow(++rownum);
}
+
+ if (rownum > getLastRowNum())
+ return -1;
+
return rownum;
}
{
HSSFRow row = new HSSFRow();
- row.setRowNum(( short ) rownum);
- return ( HSSFRow ) rows.get(row);
+ row.setRowNum((short) rownum);
+ return (HSSFRow) rows.get(row);
}
/**
return lastrow;
}
- /**
- * Seems to be unused (gjs)
- *
- * used internally to add cells from a high level row to the low level model
- * @param row the row object to represent in low level RowRecord.
- */
- private void addCellsFromRow(HSSFRow row)
- {
- Iterator iter = row.cellIterator();
-
- // for (int k = 0; k < row.getPhysicalNumberOfCells(); k++)
- while (iter.hasNext())
- {
- HSSFCell cell =
- ( HSSFCell ) iter.next(); // row.getPhysicalCellAt(k);
-
- sheet.addValueRecord(row.getRowNum(), cell.getCellValueRecord());
- }
- }
-
/**
* set the width (in units of 1/256th of a character width)
* @param column - the column to set (0-based)
/**
* get the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
- * @retun default row height
+ * @return default row height
*/
public short getDefaultRowHeight()
public void setDefaultRowHeightInPoints(float height)
{
- sheet.setDefaultRowHeight(( short ) (height * 20));
+ sheet.setDefaultRowHeight((short) (height * 20));
}
/**
public int addMergedRegion(Region region)
{
- return sheet.addMergedRegion(( short ) region.getRowFrom(),
- region.getColumnFrom(),
- ( short ) region.getRowTo(),
- region.getColumnTo());
+ return sheet.addMergedRegion((short) region.getRowFrom(),
+ region.getColumnFrom(),
+ (short) region.getRowTo(),
+ region.getColumnTo());
}
/**
public void setVerticallyCenter(boolean value)
{
VCenterRecord record =
- ( VCenterRecord ) sheet.findFirstRecordBySid(VCenterRecord.sid);
+ (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
record.setVCenter(value);
}
public boolean getVerticallyCenter(boolean value)
{
VCenterRecord record =
- ( VCenterRecord ) sheet.findFirstRecordBySid(VCenterRecord.sid);
+ (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
return record.getVCenter();
}
}
/**
- * @returns an iterator of the PHYSICAL rows. Meaning the 3rd element may not
+ * @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*/
public void setAlternativeExpression(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateExpression(b);
}
public void setAlternativeFormula(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAlternateFormula(b);
}
public void setAutobreaks(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setAutobreaks(b);
}
public void setDialog(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDialog(b);
}
public void setDisplayGuts(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setDisplayGuts(b);
}
public void setFitToPage(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setFitToPage(b);
}
public void setRowSumsBelow(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsBelow(b);
}
public void setRowSumsRight(boolean b)
{
WSBoolRecord record =
- ( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
+ (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
record.setRowSumsRight(b);
}
public boolean getAlternateExpression()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getAlternateExpression();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getAlternateExpression();
}
/**
public boolean getAlternateFormula()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getAlternateFormula();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getAlternateFormula();
}
/**
public boolean getAutobreaks()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getAutobreaks();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getAutobreaks();
}
/**
public boolean getDialog()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getDialog();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getDialog();
}
/**
public boolean getDisplayGuts()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getDisplayGuts();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getDisplayGuts();
}
/**
public boolean getFitToPage()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getFitToPage();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getFitToPage();
}
/**
public boolean getRowSumsBelow()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getRowSumsBelow();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getRowSumsBelow();
}
/**
public boolean getRowSumsRight()
{
- return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
- .getRowSumsRight();
+ return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid))
+ .getRowSumsRight();
}
}