great patch by craig@adaptivetrade.com (Craig Kelley) --

Now rows are interperated properly as ushorts versus shorts  (java ints)


PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-05-10 03:01:11 +00:00
parent 632d0a3d4e
commit d9f7985898
22 changed files with 286 additions and 88 deletions

View File

@ -347,7 +347,8 @@ public class Sheet
}
}
public int addMergedRegion(short rowFrom, short colFrom, short rowTo,
//public int addMergedRegion(short rowFrom, short colFrom, short rowTo,
public int addMergedRegion(int rowFrom, short colFrom, int rowTo,
short colTo)
{
if (merged == null)
@ -456,7 +457,8 @@ public class Sheet
* @see org.apache.poi.hssf.record.DimensionsRecord
*/
public void setDimensions(short firstrow, short firstcol, short lastrow,
//public void setDimensions(short firstrow, short firstcol, short lastrow,
public void setDimensions(int firstrow, short firstcol, int lastrow,
short lastcol)
{
log.log(log.DEBUG, "Sheet.setDimensions");
@ -627,7 +629,8 @@ public class Sheet
log.log(log.DEBUG, "create row number " + row);
RowRecord rowrec = new RowRecord();
rowrec.setRowNumber(( short ) row);
//rowrec.setRowNumber(( short ) row);
rowrec.setRowNumber(row);
rowrec.setHeight(( short ) 0xff);
rowrec.setOptimize(( short ) 0x0);
rowrec.setOptionFlags(( short ) 0x0);
@ -645,7 +648,8 @@ public class Sheet
* @see org.apache.poi.hssf.record.SSTRecord
*/
public LabelSSTRecord createLabelSST(short row, short col, int index)
//public LabelSSTRecord createLabelSST(short row, short col, int index)
public LabelSSTRecord createLabelSST(int row, short col, int index)
{
log.logFormatted(log.DEBUG, "create labelsst row,col,index %,%,%",
new int[]
@ -671,7 +675,8 @@ public class Sheet
* @return NumberRecord for that row, col containing that value as added to the sheet
*/
public NumberRecord createNumber(short row, short col, double value)
//public NumberRecord createNumber(short row, short col, double value)
public NumberRecord createNumber(int row, short col, double value)
{
log.logFormatted(log.DEBUG, "create number row,col,value %,%,%",
new double[]
@ -680,7 +685,8 @@ public class Sheet
});
NumberRecord rec = new NumberRecord();
rec.setRow(( short ) row);
//rec.setRow(( short ) row);
rec.setRow(row);
rec.setColumn(col);
rec.setValue(value);
rec.setXFIndex(( short ) 0x0f);
@ -694,15 +700,18 @@ public class Sheet
* @param col - the column the BlankRecord is a member of
*/
public BlankRecord createBlank(short row, short col)
//public BlankRecord createBlank(short row, short col)
public BlankRecord createBlank(int row, short col)
{
log.logFormatted(log.DEBUG, "create blank row,col %,%", new short[]
//log.logFormatted(log.DEBUG, "create blank row,col %,%", new short[]
log.logFormatted(log.DEBUG, "create blank row,col %,%", new int[]
{
row, col
});
BlankRecord rec = new BlankRecord();
rec.setRow(( short ) row);
//rec.setRow(( short ) row);
rec.setRow(row);
rec.setColumn(col);
rec.setXFIndex(( short ) 0x0f);
return rec;
@ -718,10 +727,12 @@ public class Sheet
* @return bogus/useless formula record
*/
public FormulaRecord createFormula(short row, short col, String formula)
//public FormulaRecord createFormula(short row, short col, String formula)
public FormulaRecord createFormula(int row, short col, String formula)
{
log.logFormatted(log.DEBUG, "create formula row,col,formula %,%,%",
new short[]
//new short[]
new int[]
{
row, col
}, formula);
@ -759,7 +770,8 @@ public class Sheet
* @param col the cell value record itself.
*/
public void addValueRecord(short row, CellValueRecordInterface col)
//public void addValueRecord(short row, CellValueRecordInterface col)
public void addValueRecord(int row, CellValueRecordInterface col)
{
checkCells();
log.logFormatted(log.DEBUG, "add value record row,loc %,%", new int[]
@ -812,7 +824,8 @@ public class Sheet
* @see org.apache.poi.hssf.record.CellValueRecordInterface
*/
public void removeValueRecord(short row, CellValueRecordInterface col)
//public void removeValueRecord(short row, CellValueRecordInterface col)
public void removeValueRecord(int row, CellValueRecordInterface col)
{
checkCells();
log.logFormatted(log.DEBUG, "remove value record row,dimsloc %,%",
@ -1135,7 +1148,8 @@ public class Sheet
*
*/
public RowRecord getRow(short rownum)
//public RowRecord getRow(short rownum)
public RowRecord getRow(int rownum)
{
log.log(log.DEBUG, "getNextRow loc= " + loc);
return rows.getRow(rownum);

View File

@ -75,7 +75,8 @@ public class BlankRecord
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0x201;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf;
@ -114,7 +115,8 @@ public class BlankRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_col = LittleEndian.getShort(data, 2 + offset);
field_3_xf = LittleEndian.getShort(data, 4 + offset);
}
@ -139,7 +141,8 @@ public class BlankRecord
* @param row the row this cell occurs within
*/
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
field_1_row = row;
}
@ -150,7 +153,8 @@ public class BlankRecord
* @return the row
*/
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -290,7 +294,8 @@ public class BlankRecord
{
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 6);
LittleEndian.putShort(data, 4 + offset, getRow());
//LittleEndian.putShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
LittleEndian.putShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
return getRecordSize();

View File

@ -74,7 +74,8 @@ public class BoolErrRecord
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0x205;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf_index;
private byte field_4_bBoolErr;
@ -123,14 +124,16 @@ public class BoolErrRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_column = LittleEndian.getShort(data, 2 + offset);
field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
field_4_bBoolErr = data[ 6 + offset ];
field_5_fError = data[ 7 + offset ];
}
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
field_1_row = row;
}
@ -176,7 +179,8 @@ public class BoolErrRecord
field_5_fError = ( byte ) 1;
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -278,7 +282,8 @@ public class BoolErrRecord
{
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 8);
LittleEndian.putShort(data, 4 + offset, getRow());
//LittleEndian.putShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
LittleEndian.putShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
data[ 10 + offset ] = field_4_bBoolErr;

View File

@ -81,7 +81,8 @@ public interface CellValueRecordInterface
* @return the row
*/
public short getRow();
//public short getRow();
public int getRow();
/**
* get the column this cell defines within the row
@ -96,7 +97,8 @@ public interface CellValueRecordInterface
* @param row the row this cell occurs within
*/
public void setRow(short row);
//public void setRow(short row);
public void setRow(int row);
/**
* set the column this cell defines within the row

View File

@ -115,7 +115,7 @@ public class DBCellRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row_offset = LittleEndian.getShort(data, 0 + offset);
field_1_row_offset = LittleEndian.getUShort(data, 0 + offset);
field_2_cell_offsets = new short[ (size - 4) / 2 ];
int element = 0;

View File

@ -83,7 +83,8 @@ public class FormulaRecord
public static final short sid =
0x06; // docs say 406...because of a bug Microsoft support site article #Q184647)
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf;
private double field_4_value;
@ -134,7 +135,8 @@ public class FormulaRecord
protected void fillFields(byte [] data, short size, int offset)
{
if (EXPERIMENTAL_FORMULA_SUPPORT_ENABLED) {
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_column = LittleEndian.getShort(data, 2 + offset);
field_3_xf = LittleEndian.getShort(data, 4 + offset);
field_4_value = LittleEndian.getDouble(data, 6 + offset);
@ -169,7 +171,8 @@ public class FormulaRecord
return stack;
}
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
field_1_row = row;
}
@ -216,7 +219,8 @@ public class FormulaRecord
field_7_expression_len = len;
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -352,7 +356,8 @@ public class FormulaRecord
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) (22 + ptgSize));
LittleEndian.putShort(data, 4 + offset, getRow());
//LittleEndian.putShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
LittleEndian.putShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
LittleEndian.putDouble(data, 10 + offset, getValue());

View File

@ -77,7 +77,8 @@ public class LabelRecord
implements CellValueRecordInterface
{
public final static short sid = 0x204;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf_index;
private short field_4_string_len;
@ -142,7 +143,8 @@ public class LabelRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_column = LittleEndian.getShort(data, 2 + offset);
field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
field_4_string_len = LittleEndian.getShort(data, 6 + offset);
@ -171,7 +173,8 @@ public class LabelRecord
field_3_xf_index = index;
}
*/
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -299,7 +302,8 @@ public class LabelRecord
* NO-OP!
*/
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
}

View File

@ -71,7 +71,8 @@ public class LabelSSTRecord
implements CellValueRecordInterface, Comparable
{
public final static short sid = 0xfd;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_column;
private short field_3_xf_index;
private int field_4_sst_index;
@ -117,13 +118,15 @@ public class LabelSSTRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_column = LittleEndian.getShort(data, 2 + offset);
field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
field_4_sst_index = LittleEndian.getInt(data, 6 + offset);
}
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
field_1_row = row;
}
@ -157,7 +160,8 @@ public class LabelSSTRecord
field_4_sst_index = index;
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -212,7 +216,8 @@ public class LabelSSTRecord
{
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 10);
LittleEndian.putShort(data, 4 + offset, getRow());
//LittleEndian.putShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short )getRow());
LittleEndian.putShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
LittleEndian.putInt(data, 10 + offset, getSSTIndex());

View File

@ -163,7 +163,8 @@ public class MergeCellsRecord
* @return new index of said area (don't depend on it if you add/remove)
*/
public int addArea(short rowfrom, short colfrom, short rowto, short colto)
//public int addArea(short rowfrom, short colfrom, short rowto, short colto)
public int addArea(int rowfrom, short colfrom, int rowto, short colto)
{
if (field_2_regions == null)
{
@ -224,9 +225,11 @@ public class MergeCellsRecord
{
MergedRegion region = getAreaAt(k);
LittleEndian.putShort(data, offset + pos, region.row_from);
//LittleEndian.putShort(data, offset + pos, region.row_from);
LittleEndian.putShort(data, offset + pos, ( short ) region.row_from);
pos += 2;
LittleEndian.putShort(data, offset + pos, region.row_to);
//LittleEndian.putShort(data, offset + pos, region.row_to);
LittleEndian.putShort(data, offset + pos, ( short ) region.row_to);
pos += 2;
LittleEndian.putShort(data, offset + pos, region.col_from);
pos += 2;
@ -283,7 +286,8 @@ public class MergeCellsRecord
* create a merged region all in one stroke.
*/
public MergedRegion(short row_from, short row_to, short col_from,
//public MergedRegion(short row_from, short row_to, short col_from,
public MergedRegion(int row_from, int row_to, short col_from,
short col_to)
{
this.row_from = row_from;
@ -296,13 +300,15 @@ public class MergeCellsRecord
* upper lefthand corner row
*/
public short row_from;
//public short row_from;
public int row_from;
/**
* lower right hand corner row
*/
public short row_to;
//public short row_to;
public int row_to;
/**
* upper right hand corner col

View File

@ -78,7 +78,8 @@ public class MulBlankRecord
extends Record
{
public final static short sid = 0xbe;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_first_col;
private short[] field_3_xfs;
private short field_4_last_col;
@ -122,7 +123,8 @@ public class MulBlankRecord
* @return row number
*/
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -178,7 +180,8 @@ public class MulBlankRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_first_col = LittleEndian.getShort(data, 2 + offset);
field_3_xfs = parseXFs(data, 4, offset, size);
field_4_last_col = LittleEndian.getShort(data,

View File

@ -77,7 +77,8 @@ public class MulRKRecord
extends Record
{
public final static short sid = 0xbd;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_first_col;
private ArrayList field_3_rks;
private short field_4_last_col;
@ -115,7 +116,8 @@ public class MulRKRecord
super(id, size, data, offset);
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -180,7 +182,8 @@ public class MulRKRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_first_col = LittleEndian.getShort(data, 2 + offset);
field_3_rks = parseRKs(data, 4, offset, size);
field_4_last_col = LittleEndian.getShort(data,

View File

@ -75,7 +75,8 @@ public class NumberRecord
implements CellValueRecordInterface, Comparable
{
public static final short sid = 0x203;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf;
private double field_4_value;
@ -122,13 +123,15 @@ public class NumberRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_col = LittleEndian.getShort(data, 2 + offset);
field_3_xf = LittleEndian.getShort(data, 4 + offset);
field_4_value = LittleEndian.getDouble(data, 6 + offset);
}
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
field_1_row = row;
}
@ -160,7 +163,8 @@ public class NumberRecord
field_4_value = value;
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -221,7 +225,8 @@ public class NumberRecord
{
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 14);
LittleEndian.putShort(data, 4 + offset, getRow());
//LittleEndian.putShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
LittleEndian.putShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
LittleEndian.putDouble(data, 10 + offset, getValue());

View File

@ -84,7 +84,8 @@ public class RKRecord
public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
public final static short RK_INTEGER = 2;
public final static short RK_INTEGER_TIMES_100 = 3;
private short field_1_row;
//private short field_1_row;
private int field_1_row;
private short field_2_col;
private short field_3_xf_index;
private int field_4_rk_number;
@ -130,13 +131,15 @@ public class RKRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row = LittleEndian.getShort(data, 0 + offset);
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = LittleEndian.getUShort(data, 0 + offset);
field_2_col = LittleEndian.getShort(data, 2 + offset);
field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
field_4_rk_number = LittleEndian.getInt(data, 6 + offset);
}
public short getRow()
//public short getRow()
public int getRow()
{
return field_1_row;
}
@ -324,7 +327,8 @@ public class RKRecord
{
}
public void setRow(short row)
//public void setRow(short row)
public void setRow(int row)
{
}

View File

@ -71,7 +71,8 @@ public class RowRecord
implements Comparable
{
public final static short sid = 0x208;
private short field_1_row_number;
//private short field_1_row_number;
private int field_1_row_number;
private short field_2_first_col;
private short field_3_last_col; // plus 1
private short field_4_height;
@ -130,7 +131,8 @@ public class RowRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_row_number = LittleEndian.getShort(data, 0 + offset);
//field_1_row_number = LittleEndian.getShort(data, 0 + offset);
field_1_row_number = LittleEndian.getUShort(data, 0 + offset);
field_2_first_col = LittleEndian.getShort(data, 2 + offset);
field_3_last_col = LittleEndian.getShort(data, 4 + offset);
field_4_height = LittleEndian.getShort(data, 6 + offset);
@ -145,7 +147,8 @@ public class RowRecord
* @param row - the row number
*/
public void setRowNumber(short row)
//public void setRowNumber(short row)
public void setRowNumber(int row)
{
field_1_row_number = row;
}
@ -281,7 +284,8 @@ public class RowRecord
* @return row - the row number
*/
public short getRowNumber()
//public short getRowNumber()
public int getRowNumber()
{
return field_1_row_number;
}
@ -451,7 +455,8 @@ public class RowRecord
{
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 16);
LittleEndian.putShort(data, 4 + offset, getRowNumber());
//LittleEndian.putShort(data, 4 + offset, getRowNumber());
LittleEndian.putShort(data, 4 + offset, ( short ) getRowNumber());
LittleEndian.putShort(data, 6 + offset, getFirstCol() == -1 ? (short)0 : getFirstCol());
LittleEndian.putShort(data, 8 + offset, getLastCol() == -1 ? (short)0 : getLastCol());
LittleEndian.putShort(data, 10 + offset, getHeight());

View File

@ -75,7 +75,8 @@ public class SelectionRecord
{
public final static short sid = 0x1d;
private byte field_1_pane;
private short field_2_row_active_cell;
//private short field_2_row_active_cell;
private int field_2_row_active_cell;
private short field_3_col_active_cell;
private short field_4_ref_active_cell;
private short field_5_num_refs;
@ -123,7 +124,8 @@ public class SelectionRecord
protected void fillFields(byte [] data, short size, int offset)
{
field_1_pane = data[ 0 + offset ];
field_2_row_active_cell = LittleEndian.getShort(data, 1 + offset);
//field_2_row_active_cell = LittleEndian.getShort(data, 1 + offset);
field_2_row_active_cell = LittleEndian.getUShort(data, 1 + offset);
field_3_col_active_cell = LittleEndian.getShort(data, 3 + offset);
field_4_ref_active_cell = LittleEndian.getShort(data, 5 + offset);
field_5_num_refs = LittleEndian.getShort(data, 7 + offset);
@ -144,7 +146,8 @@ public class SelectionRecord
* @param row number of active cell
*/
public void setActiveCellRow(short row)
//public void setActiveCellRow(short row)
public void setActiveCellRow(int row)
{
field_2_row_active_cell = row;
}
@ -194,7 +197,8 @@ public class SelectionRecord
* @return row number of active cell
*/
public short getActiveCellRow()
//public short getActiveCellRow()
public int getActiveCellRow()
{
return field_2_row_active_cell;
}
@ -254,7 +258,8 @@ public class SelectionRecord
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 15);
data[ 4 + offset ] = getPane();
LittleEndian.putShort(data, 5 + offset, getActiveCellRow());
//LittleEndian.putShort(data, 5 + offset, getActiveCellRow());
LittleEndian.putShort(data, 5 + offset, ( short ) getActiveCellRow());
LittleEndian.putShort(data, 7 + offset, getActiveCellCol());
LittleEndian.putShort(data, 9 + offset, getActiveCellRef());
LittleEndian.putShort(data, 11 + offset, ( short ) 1);

View File

@ -156,7 +156,8 @@ public class HSSFCell
private short encoding;
private Workbook book;
private Sheet sheet;
private short row;
//private short row;
private int row;
private CellValueRecordInterface record;
/**
@ -176,7 +177,8 @@ public class HSSFCell
* @see org.apache.poi.hssf.usermodel.HSSFRow#createCell(short)
*/
protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
//protected HSSFCell(Workbook book, Sheet sheet, short row, short col)
protected HSSFCell(Workbook book, Sheet sheet, int row, short col)
{
cellNum = col;
this.row = row;
@ -213,7 +215,8 @@ public class HSSFCell
* and use setCellValue to specify the type lazily.
*/
protected HSSFCell(Workbook book, Sheet sheet, short row, short col,
//protected HSSFCell(Workbook book, Sheet sheet, short row, short col,
protected HSSFCell(Workbook book, Sheet sheet, int row, short col,
int type)
{
cellNum = col;
@ -286,7 +289,8 @@ public class HSSFCell
* @param cval - the Cell Value Record we wish to represent
*/
protected HSSFCell(Workbook book, Sheet sheet, short row,
//protected HSSFCell(Workbook book, Sheet sheet, short row,
protected HSSFCell(Workbook book, Sheet sheet, int row,
CellValueRecordInterface cval)
{
cellNum = cval.getColumn();

View File

@ -82,7 +82,8 @@ public class HSSFRow
// used for collections
public final static int INITIAL_CAPACITY = 5;
private short rowNum;
//private short rowNum;
private int rowNum;
private HashMap cells;
// private short firstcell = -1;
// private short lastcell = -1;
@ -118,7 +119,8 @@ public class HSSFRow
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(short)
*/
protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
//protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
{
this.rowNum = rowNum;
cells = new HashMap(10); // new ArrayList(INITIAL_CAPACITY);
@ -145,7 +147,7 @@ public class HSSFRow
protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
{
this.rowNum = rowNum;
//this.rowNum = rowNum;
cells = new HashMap(); // ArrayList(INITIAL_CAPACITY);
this.book = book;
this.sheet = sheet;
@ -243,7 +245,8 @@ public class HSSFRow
* @param rowNum the row number (0-based)
*/
public void setRowNum(short rowNum)
//public void setRowNum(short rowNum)
public void setRowNum(int rowNum)
{
this.rowNum = rowNum;
if (row != null)
@ -257,7 +260,8 @@ public class HSSFRow
* @return the row number (0 based)
*/
public short getRowNum()
//public short getRowNum()
public int getRowNum()
{
return rowNum;
}

View File

@ -189,7 +189,8 @@ public class HSSFSheet
* @see #removeRow(HSSFRow)
*/
public HSSFRow createRow(short rownum)
//public HSSFRow createRow(short rownum)
public HSSFRow createRow(int rownum)
{
HSSFRow row = new HSSFRow(book, sheet, rownum);
@ -315,7 +316,8 @@ public class HSSFSheet
{
HSSFRow row = new HSSFRow();
row.setRowNum((short) rownum);
//row.setRowNum((short) rownum);
row.setRowNum( rownum);
return (HSSFRow) rows.get(row);
}
@ -464,9 +466,11 @@ public class HSSFSheet
public int addMergedRegion(Region region)
{
return sheet.addMergedRegion((short) region.getRowFrom(),
//return sheet.addMergedRegion((short) region.getRowFrom(),
return sheet.addMergedRegion( region.getRowFrom(),
region.getColumnFrom(),
(short) region.getRowTo(),
//(short) region.getRowTo(),
region.getRowTo(),
region.getColumnTo());
}

View File

@ -91,7 +91,28 @@ public class LittleEndian
public static short getShort(final byte[] data, final int offset)
{
return (short) getNumber(data, offset, SHORT_SIZE);
return (short)getNumber(data, offset, SHORT_SIZE);
}
/**
* get an unsigned short value from a byte array
*
* @param data the byte array
* @param offset a starting offset into the byte array
*
* @return the unsigned short (16-bit) value in an integer
*
* @exception ArrayIndexOutOfBoundsException may be thrown
*/
public static int getUShort(final byte[] data, final int offset)
{
short num = (short)getNumber(data, offset, SHORT_SIZE);
int retNum;
if (num < 0)
retNum = ((int)Short.MAX_VALUE+1)*2+(int)num;
else
retNum = (int)num;
return retNum;
}
/**
@ -132,6 +153,20 @@ public class LittleEndian
return getShort(data, 0);
}
/**
* get an unsigned short value from the beginning of a byte array
*
* @param data the byte array
*
* @return the unsigned short (16-bit) value in an int
*
* @exception ArrayIndexOutOfBoundsException may be thrown
*/
public static int getUShort(final byte[] data)
{
return getUShort(data, 0);
}
/**
* get an int value from a byte array
*

View File

@ -77,11 +77,13 @@ public class TestFormulaRecord
public void testCreateFormulaRecord () {
FormulaRecord record = new FormulaRecord();
record.setColumn((short)0);
record.setRow((short)1);
//record.setRow((short)1);
record.setRow(1);
record.setXFIndex((short)4);
assertEquals(record.getColumn(),(short)0);
assertEquals(record.getRow(),(short)1);
//assertEquals(record.getRow(),(short)1);
assertEquals((short)record.getRow(),(short)1);
assertEquals(record.getXFIndex(),(short)4);
}

View File

@ -611,6 +611,42 @@ public class TestWorkbook
assertEquals(1, sstRecords);
}
public void testManyRows()
throws Exception
{
String testName = "TestManyRows";
File file = File.createTempFile(testName, ".xls");
FileOutputStream out = new FileOutputStream(file);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = null;
HSSFCell cell = null;
int i, j;
for ( i = 0, j = 32771; j > 0; i++, j-- )
{
row = sheet.createRow(i);
cell = row.createCell((short) 0);
cell.setCellValue(i);
}
workbook.write(out);
out.close();
sanityChecker.checkHSSFWorkbook(workbook);
assertEquals("LAST ROW == 32770", 32770, sheet.getLastRowNum());
double lastVal = cell.getNumericCellValue();
FileInputStream in = new FileInputStream(file);
POIFSFileSystem fs = new POIFSFileSystem(in);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet s = wb.getSheetAt(0);
row = s.getRow(32770);
cell = row.getCell(( short ) 0);
assertEquals("Value from last row == 32770", lastVal, cell.getNumericCellValue(), 0);
assertEquals("LAST ROW == 32770", 32770, s.getLastRowNum());
in.close();
file.deleteOnExit();
}
public static void main(String [] ignored_args)
{
String filename = System.getProperty("HSSF.testdata.path");

View File

@ -101,6 +101,48 @@ public class TestLittleEndian
assertEquals(expected[ 1 ], LittleEndian.getShort(testdata, 1));
}
public void testGetUShort()
{
byte[] testdata = new byte[ LittleEndian.SHORT_SIZE + 1 ];
testdata[ 0 ] = 0x01;
testdata[ 1 ] = ( byte ) 0xFF;
testdata[ 2 ] = 0x02;
byte[] testdata2 = new byte[ LittleEndian.SHORT_SIZE + 1 ];
testdata2[ 0 ] = 0x0D;
testdata2[ 1 ] = ( byte )0x93;
testdata2[ 2 ] = ( byte )0xFF;
int expected[] = new int[ 4 ];
expected[ 0 ] = 0xFF01;
expected[ 1 ] = 0x02FF;
expected[ 2 ] = 0x930D;
expected[ 3 ] = 0xFF93;
assertEquals(expected[ 0 ], LittleEndian.getUShort(testdata));
assertEquals(expected[ 1 ], LittleEndian.getUShort(testdata, 1));
assertEquals(expected[ 2 ], LittleEndian.getUShort(testdata2));
assertEquals(expected[ 3 ], LittleEndian.getUShort(testdata2, 1));
byte[] testdata3 = new byte[ LittleEndian.SHORT_SIZE + 1 ];
LittleEndian.putShort(testdata3, 0, ( short ) expected[2] );
LittleEndian.putShort(testdata3, 1, ( short ) expected[3] );
assertEquals(testdata3[ 0 ], 0x0D);
assertEquals(testdata3[ 1 ], (byte)0x93);
assertEquals(testdata3[ 2 ], (byte)0xFF);
assertEquals(expected[ 2 ], LittleEndian.getUShort(testdata3));
assertEquals(expected[ 3 ], LittleEndian.getUShort(testdata3, 1));
//System.out.println("TD[1][0]: "+LittleEndian.getUShort(testdata)+" expecting 65281");
//System.out.println("TD[1][1]: "+LittleEndian.getUShort(testdata, 1)+" expecting 767");
//System.out.println("TD[2][0]: "+LittleEndian.getUShort(testdata2)+" expecting 37645");
//System.out.println("TD[2][1]: "+LittleEndian.getUShort(testdata2, 1)+" expecting 65427");
//System.out.println("TD[3][0]: "+LittleEndian.getUShort(testdata3)+" expecting 37645");
//System.out.println("TD[3][1]: "+LittleEndian.getUShort(testdata3, 1)+" expecting 65427");
}
private static final byte[] _double_array =
{
56, 50, -113, -4, -63, -64, -13, 63, 76, -32, -42, -35, 60, -43, 3, 64