2004-04-09 09:05:39 -04:00
|
|
|
|
2002-01-30 21:22:28 -05:00
|
|
|
/* ====================================================================
|
2004-04-09 09:05:39 -04:00
|
|
|
Copyright 2002-2004 Apache Software Foundation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HSSFRow.java
|
|
|
|
*
|
|
|
|
* Created on September 30, 2001, 3:44 PM
|
|
|
|
*/
|
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.model.Sheet;
|
2002-03-12 05:53:02 -05:00
|
|
|
import org.apache.poi.hssf.model.Workbook;
|
2002-01-30 21:22:28 -05:00
|
|
|
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
2002-03-12 05:53:02 -05:00
|
|
|
import org.apache.poi.hssf.record.RowRecord;
|
2003-07-18 22:48:17 -04:00
|
|
|
import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
|
2002-03-12 05:53:02 -05:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* High level representation of a row of a spreadsheet.
|
|
|
|
*
|
|
|
|
* Only rows that have cells should be added to a Sheet.
|
|
|
|
* @version 1.0-pre
|
|
|
|
* @author Andrew C. Oliver (acoliver at apache dot org)
|
2002-04-01 06:17:32 -05:00
|
|
|
* @author Glen Stampoultzis (glens at apache.org)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class HSSFRow
|
2002-03-12 05:53:02 -05:00
|
|
|
implements Comparable
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
// used for collections
|
|
|
|
public final static int INITIAL_CAPACITY = 5;
|
2002-05-09 23:01:11 -04:00
|
|
|
//private short rowNum;
|
|
|
|
private int rowNum;
|
2003-07-18 22:48:17 -04:00
|
|
|
//private ValueRecordsAggregate cells;
|
2002-04-01 06:17:32 -05:00
|
|
|
// private short firstcell = -1;
|
|
|
|
// private short lastcell = -1;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reference to low level representation
|
|
|
|
*/
|
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
//private RowRecord row;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reference to containing low level Workbook
|
|
|
|
*/
|
|
|
|
|
2002-03-12 05:53:02 -05:00
|
|
|
private Workbook book;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reference to containing Sheet
|
|
|
|
*/
|
|
|
|
|
2002-03-12 05:53:02 -05:00
|
|
|
private Sheet sheet;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
protected HSSFRow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates new HSSFRow from scratch. Only HSSFSheet should do this.
|
|
|
|
*
|
|
|
|
* @param book low-level Workbook object containing the sheet that contains this row
|
|
|
|
* @param sheet low-level Sheet object that contains this Row
|
|
|
|
* @param rowNum the row number of this row (0 based)
|
2003-12-06 06:01:19 -05:00
|
|
|
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
2002-05-09 23:01:11 -04:00
|
|
|
//protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
|
|
|
|
protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
this.rowNum = rowNum;
|
2003-07-18 22:48:17 -04:00
|
|
|
//cells = new HashMap(10); // new ArrayList(INITIAL_CAPACITY);
|
2002-03-12 05:53:02 -05:00
|
|
|
this.book = book;
|
|
|
|
this.sheet = sheet;
|
2003-07-18 22:48:17 -04:00
|
|
|
//row = new RowRecord();
|
|
|
|
//row.setHeight((short) 0xff);
|
|
|
|
//row.setLastCol((short) -1);
|
|
|
|
//row.setFirstCol((short) -1);
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
// row.setRowNumber(rowNum);
|
2003-07-18 22:48:17 -04:00
|
|
|
//setRowNum(rowNum);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do
|
|
|
|
* this. HSSFSheet uses this when an existing file is read in.
|
|
|
|
*
|
|
|
|
* @param book low-level Workbook object containing the sheet that contains this row
|
|
|
|
* @param sheet low-level Sheet object that contains this Row
|
2002-02-11 05:45:51 -05:00
|
|
|
* @param record the low level api object this row should represent
|
2003-12-06 06:01:19 -05:00
|
|
|
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
|
|
|
|
{
|
2002-05-09 23:01:11 -04:00
|
|
|
//this.rowNum = rowNum;
|
2003-07-18 22:48:17 -04:00
|
|
|
//cells = new HashMap(); // ArrayList(INITIAL_CAPACITY);
|
2002-03-12 05:53:02 -05:00
|
|
|
this.book = book;
|
|
|
|
this.sheet = sheet;
|
2003-07-18 22:48:17 -04:00
|
|
|
//row = record;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
// row.setHeight(record.getHeight());
|
|
|
|
// row.setRowNumber(rowNum);
|
|
|
|
setRowNum(record.getRowNumber());
|
|
|
|
|
|
|
|
// addColumns(book, sheet, record);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to create new cells within the row and return it.
|
|
|
|
* <p>
|
|
|
|
* The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
|
2002-02-27 06:12:38 -05:00
|
|
|
* either through calling <code>setCellValue</code> or <code>setCellType</code>.
|
2002-01-30 21:22:28 -05:00
|
|
|
*
|
|
|
|
* @param column - the column number this cell represents
|
|
|
|
*
|
|
|
|
* @return HSSFCell a high level representation of the created cell.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public HSSFCell createCell(short column)
|
|
|
|
{
|
|
|
|
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column);
|
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
//addCell(cell);
|
|
|
|
//sheet.addValueRecord(getRowNum(), cell.getCellValueRecord());
|
2002-01-30 21:22:28 -05:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this to create new cells within the row and return it.
|
|
|
|
* <p>
|
|
|
|
* The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
|
|
|
|
* either through calling setCellValue or setCellType.
|
|
|
|
*
|
|
|
|
* @param column - the column number this cell represents
|
|
|
|
*
|
|
|
|
* @return HSSFCell a high level representation of the created cell.
|
|
|
|
* @deprecated As of 22-Jan-2002 use createCell(short) and use setCellValue to
|
|
|
|
* specify the type lazily.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public HSSFCell createCell(short column, int type)
|
|
|
|
{
|
|
|
|
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column, type);
|
|
|
|
|
2002-03-12 05:53:02 -05:00
|
|
|
addCell(cell);
|
2002-01-30 21:22:28 -05:00
|
|
|
sheet.addValueRecord(getRowNum(), cell.getCellValueRecord());
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove the HSSFCell from this row.
|
|
|
|
* @param cell to remove
|
|
|
|
*/
|
|
|
|
public void removeCell(HSSFCell cell)
|
|
|
|
{
|
|
|
|
CellValueRecordInterface cval = cell.getCellValueRecord();
|
|
|
|
|
|
|
|
sheet.removeValueRecord(getRowNum(), cval);
|
2003-07-18 22:48:17 -04:00
|
|
|
//cells.remove(new Integer(cell.getCellNum()));
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
if (cell.getCellNum() == getLastCol(rowNum))
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
sheet.getRow(rowNum).setLastCol(findLastCell(sheet.getRow(rowNum).getLastCol()));
|
2002-04-08 10:03:37 -04:00
|
|
|
}
|
2003-07-18 22:48:17 -04:00
|
|
|
if (cell.getCellNum() == getFirstCol(rowNum))
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
setFirstCol(findFirstCell(getFirstCol(rowNum)));
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a high level HSSFCell object from an existing low level record. Should
|
|
|
|
* only be called from HSSFSheet or HSSFRow itself.
|
|
|
|
* @param cell low level cell to create the high level representation from
|
|
|
|
* @return HSSFCell representing the low level record passed in
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected HSSFCell createCellFromRecord(CellValueRecordInterface cell)
|
|
|
|
{
|
|
|
|
HSSFCell hcell = new HSSFCell(book, sheet, getRowNum(), cell);
|
|
|
|
|
2002-03-12 05:53:02 -05:00
|
|
|
addCell(hcell);
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
sheet.addValueRecord(getRowNum(),cell);
|
2002-01-30 21:22:28 -05:00
|
|
|
return hcell;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the row number of this row.
|
2002-02-11 05:45:51 -05:00
|
|
|
* @param rowNum the row number (0-based)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
2002-05-09 23:01:11 -04:00
|
|
|
//public void setRowNum(short rowNum)
|
|
|
|
public void setRowNum(int rowNum)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
this.rowNum = rowNum;
|
2003-07-18 22:48:17 -04:00
|
|
|
//if (row != null)
|
|
|
|
//{
|
|
|
|
// row.setRowNumber(rowNum); // used only for KEY comparison (HSSFRow)
|
|
|
|
//}
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get row number this row represents
|
|
|
|
* @return the row number (0 based)
|
|
|
|
*/
|
|
|
|
|
2002-05-09 23:01:11 -04:00
|
|
|
//public short getRowNum()
|
|
|
|
public int getRowNum()
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
return rowNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-04-08 10:25:16 -04:00
|
|
|
* used internally to add a cell.
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
2002-03-12 05:53:02 -05:00
|
|
|
private void addCell(HSSFCell cell)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
if (getFirstCol(rowNum) == -1)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
setFirstCol(cell.getCellNum());
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
2003-07-18 22:48:17 -04:00
|
|
|
if (getLastCol(rowNum) == -1)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
setLastCol(cell.getCellNum());
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
2003-07-18 22:48:17 -04:00
|
|
|
//cells.put(new Integer(cell.getCellNum()), cell);
|
|
|
|
sheet.addValueRecord(this.rowNum, cell.getCellValueRecord());
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
if (cell.getCellNum() < getFirstCol(rowNum))
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
setFirstCol(cell.getCellNum());
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
2003-07-18 22:48:17 -04:00
|
|
|
if (cell.getCellNum() > getLastCol(rowNum))
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
setLastCol(cell.getCellNum());
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-18 22:48:17 -04:00
|
|
|
private void setLastCol(short cell) {
|
|
|
|
sheet.setLastColForRow(rowNum, cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setFirstCol(short cell) {
|
|
|
|
sheet.setFirstColForRow(rowNum, cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
private short getLastCol(int row) {
|
|
|
|
return sheet.getLastColForRow(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
private short getFirstCol(int row) {
|
|
|
|
return sheet.getFirstColForRow(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-30 21:22:28 -05:00
|
|
|
/**
|
|
|
|
* get the hssfcell representing a given column (logical cell) 0-based. If you
|
|
|
|
* ask for a cell that is not defined....you get a null.
|
|
|
|
*
|
2002-04-24 10:35:12 -04:00
|
|
|
* @param cellnum 0 based column number
|
|
|
|
* @return HSSFCell representing that column or null if undefined.
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
public HSSFCell getCell(short cellnum)
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
HSSFCell retval = null;
|
|
|
|
CellValueRecordInterface cval = sheet.getValueRecord(rowNum, cellnum);
|
|
|
|
if (cval != null) {
|
|
|
|
retval = new HSSFCell(book, sheet, rowNum, cval);
|
|
|
|
}
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
/* for (int k = 0; k < cells.size(); k++)
|
|
|
|
{
|
|
|
|
HSSFCell cell = ( HSSFCell ) cells.get(k);
|
|
|
|
|
|
|
|
if (cell.getCellNum() == cellnum)
|
|
|
|
{
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}*/
|
2003-07-18 22:48:17 -04:00
|
|
|
return retval;
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the number of the first cell contained in this row.
|
|
|
|
* @return short representing the first logical cell in the row
|
|
|
|
*/
|
|
|
|
|
|
|
|
public short getFirstCellNum()
|
|
|
|
{
|
2002-04-28 01:22:19 -04:00
|
|
|
if (getPhysicalNumberOfCells() == 0)
|
|
|
|
return -1;
|
|
|
|
else
|
2003-07-18 22:48:17 -04:00
|
|
|
return getFirstCol(rowNum);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the number of the last cell contained in this row.
|
|
|
|
* @return short representing the last logical cell in the row
|
|
|
|
*/
|
|
|
|
|
|
|
|
public short getLastCellNum()
|
|
|
|
{
|
2002-04-28 01:22:19 -04:00
|
|
|
if (getPhysicalNumberOfCells() == 0)
|
|
|
|
return -1;
|
|
|
|
else
|
2003-07-18 22:48:17 -04:00
|
|
|
return getLastCol(rowNum);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gets the number of defined cells (NOT number of cells in the actual row!).
|
|
|
|
* That is to say if only columns 0,4,5 have values then there would be 3.
|
|
|
|
* @return int representing the number of defined cells in the row.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public int getPhysicalNumberOfCells()
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
// sheet.get
|
|
|
|
// if (cells == null)
|
|
|
|
// {
|
|
|
|
// return 0; // shouldn't be possible but it is due to missing API support for BLANK/MULBLANK
|
|
|
|
// }
|
|
|
|
// return cells.size();
|
|
|
|
return sheet.getPhysicalNumberOfRows();
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the row's height or set to ff (-1) for undefined/default-height. Set the height in "twips" or
|
|
|
|
* 1/20th of a point.
|
2002-02-11 05:45:51 -05:00
|
|
|
* @param height rowheight or 0xff for undefined (use sheet default)
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
public void setHeight(short height)
|
|
|
|
{
|
|
|
|
|
|
|
|
// row.setOptionFlags(
|
2003-07-18 22:48:17 -04:00
|
|
|
sheet.getRow(rowNum).setBadFontHeight(true);
|
|
|
|
sheet.getRow(rowNum).setHeight(height);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the row's height in points.
|
2002-02-11 05:45:51 -05:00
|
|
|
* @param height row height in points
|
2002-01-30 21:22:28 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
public void setHeightInPoints(float height)
|
|
|
|
{
|
|
|
|
|
|
|
|
// row.setOptionFlags(
|
2003-07-18 22:48:17 -04:00
|
|
|
sheet.getRow(rowNum).setBadFontHeight(true);
|
|
|
|
sheet.getRow(rowNum).setHeight((short) (height * 20));
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)
|
|
|
|
* @return rowheight or 0xff for undefined (use sheet default)
|
|
|
|
*/
|
|
|
|
|
|
|
|
public short getHeight()
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
return sheet.getRow(rowNum).getHeight();
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the row's height or ff (-1) for undefined/default-height in points (20*getHeight())
|
|
|
|
* @return rowheight or 0xff for undefined (use sheet default)
|
|
|
|
*/
|
|
|
|
|
|
|
|
public float getHeightInPoints()
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
return (sheet.getRow(rowNum).getHeight() / 20);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the lowlevel RowRecord represented by this object - should only be called
|
|
|
|
* by other parts of the high level API
|
|
|
|
*
|
|
|
|
* @return RowRecord this row represents
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected RowRecord getRowRecord()
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
return sheet.getRow(rowNum);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* used internally to refresh the "last cell" when the last cell is removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private short findLastCell(short lastcell)
|
|
|
|
{
|
2002-03-12 05:53:02 -05:00
|
|
|
short cellnum = (short) (lastcell - 1);
|
|
|
|
HSSFCell r = getCell(cellnum);
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2002-04-08 08:46:40 -04:00
|
|
|
while (r == null && cellnum >= 0)
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
r = getCell(--cellnum);
|
|
|
|
}
|
|
|
|
return cellnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* used internally to refresh the "first cell" when the first cell is removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private short findFirstCell(short firstcell)
|
|
|
|
{
|
2002-03-12 05:53:02 -05:00
|
|
|
short cellnum = (short) (firstcell + 1);
|
|
|
|
HSSFCell r = getCell(cellnum);
|
2002-01-30 21:22:28 -05:00
|
|
|
|
2002-04-08 10:03:37 -04:00
|
|
|
while (r == null && cellnum <= getLastCellNum())
|
2002-01-30 21:22:28 -05:00
|
|
|
{
|
|
|
|
r = getCell(++cellnum);
|
|
|
|
}
|
2002-04-08 10:03:37 -04:00
|
|
|
if (cellnum > getLastCellNum())
|
|
|
|
return -1;
|
2002-01-30 21:22:28 -05:00
|
|
|
return cellnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-04-24 10:35:12 -04:00
|
|
|
* @return cell iterator of the physically defined cells. Note element 4 may
|
2002-01-30 21:22:28 -05:00
|
|
|
* actually be row cell depending on how many are defined!
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Iterator cellIterator()
|
|
|
|
{
|
2003-07-18 22:48:17 -04:00
|
|
|
return new RowCellIterator(this.book, this.sheet, this.rowNum);
|
2002-01-30 21:22:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int compareTo(Object obj)
|
|
|
|
{
|
2002-03-12 05:53:02 -05:00
|
|
|
HSSFRow loc = (HSSFRow) obj;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
if (this.getRowNum() == loc.getRowNum())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (this.getRowNum() < loc.getRowNum())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (this.getRowNum() > loc.getRowNum())
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object obj)
|
|
|
|
{
|
|
|
|
if (!(obj instanceof HSSFRow))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-03-12 05:53:02 -05:00
|
|
|
HSSFRow loc = (HSSFRow) obj;
|
2002-01-30 21:22:28 -05:00
|
|
|
|
|
|
|
if (this.getRowNum() == loc.getRowNum())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-07-18 22:48:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
class RowCellIterator implements Iterator {
|
|
|
|
Iterator cells;
|
|
|
|
Workbook book;
|
|
|
|
Sheet sheet;
|
|
|
|
int row;
|
|
|
|
|
|
|
|
public RowCellIterator(Workbook book, Sheet sheet, int row) {
|
|
|
|
this.sheet = sheet;
|
|
|
|
this.book = book;
|
|
|
|
this.row = row;
|
|
|
|
cells = this.sheet.rowCellIterator(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasNext() {
|
|
|
|
return cells.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object next() {
|
|
|
|
HSSFCell retval = null;
|
|
|
|
if (cells.hasNext()) {
|
|
|
|
retval = new HSSFCell(book, sheet, row, ((CellValueRecordInterface)cells.next()));
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void remove() {
|
|
|
|
cells.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-09 09:05:39 -04:00
|
|
|
}
|