/* ==================================================================== 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. ==================================================================== */ /* * HSSFRow.java * * Created on September 30, 2001, 3:44 PM */ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.RowRecord; import java.util.HashMap; import java.util.Iterator; import java.util.NoSuchElementException; /** * 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) * @author Glen Stampoultzis (glens at apache.org) */ public class HSSFRow implements Comparable { // used for collections public final static int INITIAL_CAPACITY = 5; //private short rowNum; private int rowNum; private HSSFCell[] cells=new HSSFCell[INITIAL_CAPACITY]; // private short firstcell = -1; // private short lastcell = -1; /** * reference to low level representation */ private RowRecord row; /** * reference to containing low level Workbook */ private Workbook book; /** * reference to containing Sheet */ private Sheet sheet; 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) * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) */ //protected HSSFRow(Workbook book, Sheet sheet, short rowNum) protected HSSFRow(Workbook book, Sheet sheet, int rowNum) { this.rowNum = rowNum; this.book = book; this.sheet = sheet; row = new RowRecord(); row.setOptionFlags( (short)0x100 ); // seems necessary for outlining to work. row.setHeight((short) 0xff); row.setLastCol((short) -1); row.setFirstCol((short) -1); setRowNum(rowNum); } /** * 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 * @param record the low level api object this row should represent * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) */ protected HSSFRow(Workbook book, Sheet sheet, RowRecord record) { this.book = book; this.sheet = sheet; row = record; setRowNum(record.getRowNumber()); } /** * Use this to create new cells within the row and return it. *
* 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.
*/
public HSSFCell createCell(short column)
{
return this.createCell(column,HSSFCell.CELL_TYPE_BLANK);
}
/**
* Use this to create new cells within the row and return it.
*
* 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.
*/
public HSSFCell createCell(short column, int type)
{
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), column, type);
addCell(cell);
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);
short column=cell.getCellNum();
if(cell!=null && column