Fix for bug 46654 - HSSFRow/RowRecord needs to properly update cell boundary indexes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@741036 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3fe60b8acf
commit
aac8563019
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.5-beta5" date="2008-??-??">
|
<release version="3.5-beta5" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">46654 - HSSFRow/RowRecord to properly update cell boundary indexes</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
|
<action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
|
<action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
|
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.5-beta5" date="2008-??-??">
|
<release version="3.5-beta5" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">46654 - HSSFRow/RowRecord to properly update cell boundary indexes</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
|
<action dev="POI-DEVELOPERS" type="fix">46643 - Fixed formula parser to encode range operator with tMemFunc</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
|
<action dev="POI-DEVELOPERS" type="fix">46647 - Fixed COUNTIF NE operator and other special cases involving type conversion</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
|
<action dev="POI-DEVELOPERS" type="add">46635 - Added a method to remove slides</action>
|
||||||
|
@ -40,6 +40,7 @@ import org.apache.poi.hssf.record.GutsRecord;
|
|||||||
import org.apache.poi.hssf.record.IndexRecord;
|
import org.apache.poi.hssf.record.IndexRecord;
|
||||||
import org.apache.poi.hssf.record.IterationRecord;
|
import org.apache.poi.hssf.record.IterationRecord;
|
||||||
import org.apache.poi.hssf.record.MergeCellsRecord;
|
import org.apache.poi.hssf.record.MergeCellsRecord;
|
||||||
|
import org.apache.poi.hssf.record.NoteRecord;
|
||||||
import org.apache.poi.hssf.record.ObjRecord;
|
import org.apache.poi.hssf.record.ObjRecord;
|
||||||
import org.apache.poi.hssf.record.ObjectProtectRecord;
|
import org.apache.poi.hssf.record.ObjectProtectRecord;
|
||||||
import org.apache.poi.hssf.record.PaneRecord;
|
import org.apache.poi.hssf.record.PaneRecord;
|
||||||
@ -1795,4 +1796,23 @@ public final class Sheet implements Model {
|
|||||||
}
|
}
|
||||||
return _dataValidityTable;
|
return _dataValidityTable;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the {@link NoteRecord}s (related to cell comments) for this sheet
|
||||||
|
* @return never <code>null</code>, typically empty array
|
||||||
|
*/
|
||||||
|
public NoteRecord[] getNoteRecords() {
|
||||||
|
List<NoteRecord> temp = new ArrayList<NoteRecord>();
|
||||||
|
for(int i=records.size()-1; i>=0; i--) {
|
||||||
|
RecordBase rec = records.get(i);
|
||||||
|
if (rec instanceof NoteRecord) {
|
||||||
|
temp.add((NoteRecord) rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (temp.size() < 1) {
|
||||||
|
return NoteRecord.EMPTY_ARRAY;
|
||||||
|
}
|
||||||
|
NoteRecord[] result = new NoteRecord[temp.size()];
|
||||||
|
temp.toArray(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,22 +26,24 @@ import org.apache.poi.util.StringUtil;
|
|||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public final class NoteRecord extends StandardRecord {
|
public final class NoteRecord extends StandardRecord {
|
||||||
public final static short sid = 0x001C;
|
public final static short sid = 0x001C;
|
||||||
|
|
||||||
/**
|
public static final NoteRecord[] EMPTY_ARRAY = { };
|
||||||
* Flag indicating that the comment is hidden (default)
|
|
||||||
*/
|
|
||||||
public final static short NOTE_HIDDEN = 0x0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag indicating that the comment is visible
|
* Flag indicating that the comment is hidden (default)
|
||||||
*/
|
*/
|
||||||
public final static short NOTE_VISIBLE = 0x2;
|
public final static short NOTE_HIDDEN = 0x0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag indicating that the comment is visible
|
||||||
|
*/
|
||||||
|
public final static short NOTE_VISIBLE = 0x2;
|
||||||
|
|
||||||
private static final Byte DEFAULT_PADDING = new Byte((byte)0);
|
private static final Byte DEFAULT_PADDING = new Byte((byte)0);
|
||||||
|
|
||||||
private short field_1_row;
|
private int field_1_row;
|
||||||
private short field_2_col;
|
private int field_2_col;
|
||||||
private short field_3_flags;
|
private short field_3_flags;
|
||||||
private short field_4_shapeid;
|
private short field_4_shapeid;
|
||||||
private boolean field_5_hasMultibyte;
|
private boolean field_5_hasMultibyte;
|
||||||
@ -54,180 +56,180 @@ public final class NoteRecord extends StandardRecord {
|
|||||||
*/
|
*/
|
||||||
private Byte field_7_padding;
|
private Byte field_7_padding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new <code>NoteRecord</code> and
|
* Construct a new <code>NoteRecord</code> and
|
||||||
* fill its data with the default values
|
* fill its data with the default values
|
||||||
*/
|
*/
|
||||||
public NoteRecord() {
|
public NoteRecord() {
|
||||||
field_6_author = "";
|
field_6_author = "";
|
||||||
field_3_flags = 0;
|
field_3_flags = 0;
|
||||||
field_7_padding = DEFAULT_PADDING; // seems to be always present regardless of author text
|
field_7_padding = DEFAULT_PADDING; // seems to be always present regardless of author text
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return id of this record.
|
* @return id of this record.
|
||||||
*/
|
*/
|
||||||
public short getSid() {
|
public short getSid() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the record data from the supplied <code>RecordInputStream</code>
|
* Read the record data from the supplied <code>RecordInputStream</code>
|
||||||
*/
|
*/
|
||||||
public NoteRecord(RecordInputStream in) {
|
public NoteRecord(RecordInputStream in) {
|
||||||
field_1_row = in.readShort();
|
field_1_row = in.readShort();
|
||||||
field_2_col = in.readShort();
|
field_2_col = in.readShort();
|
||||||
field_3_flags = in.readShort();
|
field_3_flags = in.readShort();
|
||||||
field_4_shapeid = in.readShort();
|
field_4_shapeid = in.readShort();
|
||||||
int length = in.readShort();
|
int length = in.readShort();
|
||||||
field_5_hasMultibyte = in.readByte() != 0x00;
|
field_5_hasMultibyte = in.readByte() != 0x00;
|
||||||
if (field_5_hasMultibyte) {
|
if (field_5_hasMultibyte) {
|
||||||
field_6_author = StringUtil.readUnicodeLE(in, length);
|
field_6_author = StringUtil.readUnicodeLE(in, length);
|
||||||
} else {
|
} else {
|
||||||
field_6_author = StringUtil.readCompressedUnicode(in, length);
|
field_6_author = StringUtil.readCompressedUnicode(in, length);
|
||||||
}
|
}
|
||||||
if (in.available() == 1) {
|
if (in.available() == 1) {
|
||||||
field_7_padding = new Byte(in.readByte());
|
field_7_padding = new Byte(in.readByte());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serialize(LittleEndianOutput out) {
|
public void serialize(LittleEndianOutput out) {
|
||||||
out.writeShort(field_1_row);
|
out.writeShort(field_1_row);
|
||||||
out.writeShort(field_2_col);
|
out.writeShort(field_2_col);
|
||||||
out.writeShort(field_3_flags);
|
out.writeShort(field_3_flags);
|
||||||
out.writeShort(field_4_shapeid);
|
out.writeShort(field_4_shapeid);
|
||||||
out.writeShort(field_6_author.length());
|
out.writeShort(field_6_author.length());
|
||||||
out.writeByte(field_5_hasMultibyte ? 0x01 : 0x00);
|
out.writeByte(field_5_hasMultibyte ? 0x01 : 0x00);
|
||||||
if (field_5_hasMultibyte) {
|
if (field_5_hasMultibyte) {
|
||||||
StringUtil.putUnicodeLE(field_6_author, out);
|
StringUtil.putUnicodeLE(field_6_author, out);
|
||||||
} else {
|
} else {
|
||||||
StringUtil.putCompressedUnicode(field_6_author, out);
|
StringUtil.putCompressedUnicode(field_6_author, out);
|
||||||
}
|
}
|
||||||
if (field_7_padding != null) {
|
if (field_7_padding != null) {
|
||||||
out.writeByte(field_7_padding.intValue());
|
out.writeByte(field_7_padding.intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getDataSize() {
|
protected int getDataSize() {
|
||||||
return 11 // 5 shorts + 1 byte
|
return 11 // 5 shorts + 1 byte
|
||||||
+ field_6_author.length() * (field_5_hasMultibyte ? 2 : 1)
|
+ field_6_author.length() * (field_5_hasMultibyte ? 2 : 1)
|
||||||
+ (field_7_padding == null ? 0 : 1);
|
+ (field_7_padding == null ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert this record to string.
|
* Convert this record to string.
|
||||||
* Used by BiffViewer and other utilities.
|
* Used by BiffViewer and other utilities.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append("[NOTE]\n");
|
buffer.append("[NOTE]\n");
|
||||||
buffer.append(" .row = ").append(field_1_row).append("\n");
|
buffer.append(" .row = ").append(field_1_row).append("\n");
|
||||||
buffer.append(" .col = ").append(field_2_col).append("\n");
|
buffer.append(" .col = ").append(field_2_col).append("\n");
|
||||||
buffer.append(" .flags = ").append(field_3_flags).append("\n");
|
buffer.append(" .flags = ").append(field_3_flags).append("\n");
|
||||||
buffer.append(" .shapeid= ").append(field_4_shapeid).append("\n");
|
buffer.append(" .shapeid= ").append(field_4_shapeid).append("\n");
|
||||||
buffer.append(" .author = ").append(field_6_author).append("\n");
|
buffer.append(" .author = ").append(field_6_author).append("\n");
|
||||||
buffer.append("[/NOTE]\n");
|
buffer.append("[/NOTE]\n");
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the row that contains the comment
|
* Return the row that contains the comment
|
||||||
*
|
*
|
||||||
* @return the row that contains the comment
|
* @return the row that contains the comment
|
||||||
*/
|
*/
|
||||||
public short getRow(){
|
public int getRow() {
|
||||||
return field_1_row;
|
return field_1_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the row that contains the comment
|
* Specify the row that contains the comment
|
||||||
*
|
*
|
||||||
* @param row the row that contains the comment
|
* @param row the row that contains the comment
|
||||||
*/
|
*/
|
||||||
public void setRow(short row){
|
public void setRow(int row) {
|
||||||
field_1_row = row;
|
field_1_row = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the column that contains the comment
|
* Return the column that contains the comment
|
||||||
*
|
*
|
||||||
* @return the column that contains the comment
|
* @return the column that contains the comment
|
||||||
*/
|
*/
|
||||||
public short getColumn(){
|
public int getColumn() {
|
||||||
return field_2_col;
|
return field_2_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the column that contains the comment
|
* Specify the column that contains the comment
|
||||||
*
|
*
|
||||||
* @param col the column that contains the comment
|
* @param col the column that contains the comment
|
||||||
*/
|
*/
|
||||||
public void setColumn(short col){
|
public void setColumn(int col) {
|
||||||
field_2_col = col;
|
field_2_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options flags.
|
* Options flags.
|
||||||
*
|
*
|
||||||
* @return the options flag
|
* @return the options flag
|
||||||
* @see #NOTE_VISIBLE
|
* @see #NOTE_VISIBLE
|
||||||
* @see #NOTE_HIDDEN
|
* @see #NOTE_HIDDEN
|
||||||
*/
|
*/
|
||||||
public short getFlags(){
|
public short getFlags() {
|
||||||
return field_3_flags;
|
return field_3_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options flag
|
* Options flag
|
||||||
*
|
*
|
||||||
* @param flags the options flag
|
* @param flags the options flag
|
||||||
* @see #NOTE_VISIBLE
|
* @see #NOTE_VISIBLE
|
||||||
* @see #NOTE_HIDDEN
|
* @see #NOTE_HIDDEN
|
||||||
*/
|
*/
|
||||||
public void setFlags(short flags){
|
public void setFlags(short flags) {
|
||||||
field_3_flags = flags;
|
field_3_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object id for OBJ record that contains the comment
|
* Object id for OBJ record that contains the comment
|
||||||
*/
|
*/
|
||||||
public short getShapeId(){
|
public short getShapeId() {
|
||||||
return field_4_shapeid;
|
return field_4_shapeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object id for OBJ record that contains the comment
|
* Object id for OBJ record that contains the comment
|
||||||
*/
|
*/
|
||||||
public void setShapeId(short id){
|
public void setShapeId(short id) {
|
||||||
field_4_shapeid = id;
|
field_4_shapeid = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the original comment author
|
* Name of the original comment author
|
||||||
*
|
*
|
||||||
* @return the name of the original author of the comment
|
* @return the name of the original author of the comment
|
||||||
*/
|
*/
|
||||||
public String getAuthor(){
|
public String getAuthor() {
|
||||||
return field_6_author;
|
return field_6_author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the original comment author
|
* Name of the original comment author
|
||||||
*
|
*
|
||||||
* @param author the name of the original author of the comment
|
* @param author the name of the original author of the comment
|
||||||
*/
|
*/
|
||||||
public void setAuthor(String author){
|
public void setAuthor(String author) {
|
||||||
field_6_author = author;
|
field_6_author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
NoteRecord rec = new NoteRecord();
|
NoteRecord rec = new NoteRecord();
|
||||||
rec.field_1_row = field_1_row;
|
rec.field_1_row = field_1_row;
|
||||||
rec.field_2_col = field_2_col;
|
rec.field_2_col = field_2_col;
|
||||||
rec.field_3_flags = field_3_flags;
|
rec.field_3_flags = field_3_flags;
|
||||||
rec.field_4_shapeid = field_4_shapeid;
|
rec.field_4_shapeid = field_4_shapeid;
|
||||||
rec.field_6_author = field_6_author;
|
rec.field_6_author = field_6_author;
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,16 +43,16 @@ public final class RowRecord extends StandardRecord {
|
|||||||
*/
|
*/
|
||||||
public final static int MAX_ROW_NUMBER = 65535;
|
public final static int MAX_ROW_NUMBER = 65535;
|
||||||
|
|
||||||
private int field_1_row_number;
|
private int field_1_row_number;
|
||||||
private short field_2_first_col;
|
private int field_2_first_col;
|
||||||
private short field_3_last_col; // plus 1
|
private int field_3_last_col; // plus 1
|
||||||
private short field_4_height;
|
private short field_4_height;
|
||||||
private short field_5_optimize; // hint field for gui, can/should be set to zero
|
private short field_5_optimize; // hint field for gui, can/should be set to zero
|
||||||
|
|
||||||
// for generated sheets.
|
// for generated sheets.
|
||||||
private short field_6_reserved;
|
private short field_6_reserved;
|
||||||
/** 16 bit options flags */
|
/** 16 bit options flags */
|
||||||
private int field_7_option_flags;
|
private int field_7_option_flags;
|
||||||
private static final BitField outlineLevel = BitFieldFactory.getInstance(0x07);
|
private static final BitField outlineLevel = BitFieldFactory.getInstance(0x07);
|
||||||
|
|
||||||
// bit 3 reserved
|
// bit 3 reserved
|
||||||
@ -60,22 +60,20 @@ public final class RowRecord extends StandardRecord {
|
|||||||
private static final BitField zeroHeight = BitFieldFactory.getInstance(0x20);
|
private static final BitField zeroHeight = BitFieldFactory.getInstance(0x20);
|
||||||
private static final BitField badFontHeight = BitFieldFactory.getInstance(0x40);
|
private static final BitField badFontHeight = BitFieldFactory.getInstance(0x40);
|
||||||
private static final BitField formatted = BitFieldFactory.getInstance(0x80);
|
private static final BitField formatted = BitFieldFactory.getInstance(0x80);
|
||||||
private short field_8_xf_index; // only if isFormatted
|
private short field_8_xf_index; // only if isFormatted
|
||||||
|
|
||||||
public RowRecord(int rowNumber) {
|
public RowRecord(int rowNumber) {
|
||||||
field_1_row_number = rowNumber;
|
field_1_row_number = rowNumber;
|
||||||
field_2_first_col = -1;
|
|
||||||
field_3_last_col = -1;
|
|
||||||
field_4_height = (short)0xFF;
|
field_4_height = (short)0xFF;
|
||||||
field_5_optimize = ( short ) 0;
|
field_5_optimize = ( short ) 0;
|
||||||
field_6_reserved = ( short ) 0;
|
field_6_reserved = ( short ) 0;
|
||||||
field_7_option_flags = OPTION_BITS_ALWAYS_SET; // seems necessary for outlining
|
field_7_option_flags = OPTION_BITS_ALWAYS_SET; // seems necessary for outlining
|
||||||
|
|
||||||
field_8_xf_index = ( short ) 0xf;
|
field_8_xf_index = ( short ) 0xf;
|
||||||
|
setEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowRecord(RecordInputStream in)
|
public RowRecord(RecordInputStream in) {
|
||||||
{
|
|
||||||
field_1_row_number = in.readUShort();
|
field_1_row_number = in.readUShort();
|
||||||
field_2_first_col = in.readShort();
|
field_2_first_col = in.readShort();
|
||||||
field_3_last_col = in.readShort();
|
field_3_last_col = in.readShort();
|
||||||
@ -86,12 +84,23 @@ public final class RowRecord extends StandardRecord {
|
|||||||
field_8_xf_index = in.readShort();
|
field_8_xf_index = in.readShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the firstCol and lastCol fields to the reserved value (-1)
|
||||||
|
* to signify that this row is empty
|
||||||
|
*/
|
||||||
|
public void setEmpty() {
|
||||||
|
field_2_first_col = 0;
|
||||||
|
field_3_last_col = 0;
|
||||||
|
}
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return (field_2_first_col | field_3_last_col) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the logical row number for this row (0 based index)
|
* set the logical row number for this row (0 based index)
|
||||||
* @param row - the row number
|
* @param row - the row number
|
||||||
*/
|
*/
|
||||||
public void setRowNumber(int row)
|
public void setRowNumber(int row) {
|
||||||
{
|
|
||||||
field_1_row_number = row;
|
field_1_row_number = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,17 +108,14 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set the logical col number for the first cell this row (0 based index)
|
* set the logical col number for the first cell this row (0 based index)
|
||||||
* @param col - the col number
|
* @param col - the col number
|
||||||
*/
|
*/
|
||||||
public void setFirstCol(short col)
|
public void setFirstCol(int col) {
|
||||||
{
|
|
||||||
field_2_first_col = col;
|
field_2_first_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the logical col number for the last cell this row (0 based index)
|
* @param col - one past the zero-based index to the last cell in this row
|
||||||
* @param col - the col number
|
|
||||||
*/
|
*/
|
||||||
public void setLastCol(short col)
|
public void setLastCol(int col) {
|
||||||
{
|
|
||||||
field_3_last_col = col;
|
field_3_last_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +123,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set the height of the row
|
* set the height of the row
|
||||||
* @param height of the row
|
* @param height of the row
|
||||||
*/
|
*/
|
||||||
public void setHeight(short height)
|
public void setHeight(short height) {
|
||||||
{
|
|
||||||
field_4_height = height;
|
field_4_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +131,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set whether to optimize or not (set to 0)
|
* set whether to optimize or not (set to 0)
|
||||||
* @param optimize (set to 0)
|
* @param optimize (set to 0)
|
||||||
*/
|
*/
|
||||||
public void setOptimize(short optimize)
|
public void setOptimize(short optimize) {
|
||||||
{
|
|
||||||
field_5_optimize = optimize;
|
field_5_optimize = optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,8 +141,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set the outline level of this row
|
* set the outline level of this row
|
||||||
* @param ol - the outline level
|
* @param ol - the outline level
|
||||||
*/
|
*/
|
||||||
public void setOutlineLevel(short ol)
|
public void setOutlineLevel(short ol) {
|
||||||
{
|
|
||||||
field_7_option_flags = outlineLevel.setValue(field_7_option_flags, ol);
|
field_7_option_flags = outlineLevel.setValue(field_7_option_flags, ol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +149,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set whether or not to collapse this row
|
* set whether or not to collapse this row
|
||||||
* @param c - collapse or not
|
* @param c - collapse or not
|
||||||
*/
|
*/
|
||||||
public void setColapsed(boolean c)
|
public void setColapsed(boolean c) {
|
||||||
{
|
|
||||||
field_7_option_flags = colapsed.setBoolean(field_7_option_flags, c);
|
field_7_option_flags = colapsed.setBoolean(field_7_option_flags, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +157,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set whether or not to display this row with 0 height
|
* set whether or not to display this row with 0 height
|
||||||
* @param z height is zero or not.
|
* @param z height is zero or not.
|
||||||
*/
|
*/
|
||||||
public void setZeroHeight(boolean z)
|
public void setZeroHeight(boolean z) {
|
||||||
{
|
|
||||||
field_7_option_flags = zeroHeight.setBoolean(field_7_option_flags, z);
|
field_7_option_flags = zeroHeight.setBoolean(field_7_option_flags, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,8 +165,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set whether the font and row height are not compatible
|
* set whether the font and row height are not compatible
|
||||||
* @param f true if they aren't compatible (damn not logic)
|
* @param f true if they aren't compatible (damn not logic)
|
||||||
*/
|
*/
|
||||||
public void setBadFontHeight(boolean f)
|
public void setBadFontHeight(boolean f) {
|
||||||
{
|
|
||||||
field_7_option_flags = badFontHeight.setBoolean(field_7_option_flags, f);
|
field_7_option_flags = badFontHeight.setBoolean(field_7_option_flags, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +173,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* set whether the row has been formatted (even if its got all blank cells)
|
* set whether the row has been formatted (even if its got all blank cells)
|
||||||
* @param f formatted or not
|
* @param f formatted or not
|
||||||
*/
|
*/
|
||||||
public void setFormatted(boolean f)
|
public void setFormatted(boolean f) {
|
||||||
{
|
|
||||||
field_7_option_flags = formatted.setBoolean(field_7_option_flags, f);
|
field_7_option_flags = formatted.setBoolean(field_7_option_flags, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +184,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @see org.apache.poi.hssf.record.ExtendedFormatRecord
|
* @see org.apache.poi.hssf.record.ExtendedFormatRecord
|
||||||
* @param index to the XF record
|
* @param index to the XF record
|
||||||
*/
|
*/
|
||||||
public void setXFIndex(short index)
|
public void setXFIndex(short index) {
|
||||||
{
|
|
||||||
field_8_xf_index = index;
|
field_8_xf_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,8 +192,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* get the logical row number for this row (0 based index)
|
* get the logical row number for this row (0 based index)
|
||||||
* @return row - the row number
|
* @return row - the row number
|
||||||
*/
|
*/
|
||||||
public int getRowNumber()
|
public int getRowNumber() {
|
||||||
{
|
|
||||||
return field_1_row_number;
|
return field_1_row_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,17 +200,15 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* get the logical col number for the first cell this row (0 based index)
|
* get the logical col number for the first cell this row (0 based index)
|
||||||
* @return col - the col number
|
* @return col - the col number
|
||||||
*/
|
*/
|
||||||
public short getFirstCol()
|
public int getFirstCol() {
|
||||||
{
|
|
||||||
return field_2_first_col;
|
return field_2_first_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the logical col number for the last cell this row plus one (0 based index)
|
* get the logical col number for the last cell this row (0 based index), plus one
|
||||||
* @return col - the last col number + 1
|
* @return col - the last col index + 1
|
||||||
*/
|
*/
|
||||||
public short getLastCol()
|
public int getLastCol() {
|
||||||
{
|
|
||||||
return field_3_last_col;
|
return field_3_last_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,8 +216,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* get the height of the row
|
* get the height of the row
|
||||||
* @return height of the row
|
* @return height of the row
|
||||||
*/
|
*/
|
||||||
public short getHeight()
|
public short getHeight() {
|
||||||
{
|
|
||||||
return field_4_height;
|
return field_4_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,8 +224,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* get whether to optimize or not (set to 0)
|
* get whether to optimize or not (set to 0)
|
||||||
* @return optimize (set to 0)
|
* @return optimize (set to 0)
|
||||||
*/
|
*/
|
||||||
public short getOptimize()
|
public short getOptimize() {
|
||||||
{
|
|
||||||
return field_5_optimize;
|
return field_5_optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,8 +233,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* method)
|
* method)
|
||||||
* @return options - the bitmask
|
* @return options - the bitmask
|
||||||
*/
|
*/
|
||||||
public short getOptionFlags()
|
public short getOptionFlags() {
|
||||||
{
|
|
||||||
return (short)field_7_option_flags;
|
return (short)field_7_option_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,8 +244,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @return ol - the outline level
|
* @return ol - the outline level
|
||||||
* @see #getOptionFlags()
|
* @see #getOptionFlags()
|
||||||
*/
|
*/
|
||||||
public short getOutlineLevel()
|
public short getOutlineLevel() {
|
||||||
{
|
|
||||||
return (short)outlineLevel.getValue(field_7_option_flags);
|
return (short)outlineLevel.getValue(field_7_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,8 +253,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @return c - colapse or not
|
* @return c - colapse or not
|
||||||
* @see #getOptionFlags()
|
* @see #getOptionFlags()
|
||||||
*/
|
*/
|
||||||
public boolean getColapsed()
|
public boolean getColapsed() {
|
||||||
{
|
|
||||||
return (colapsed.isSet(field_7_option_flags));
|
return (colapsed.isSet(field_7_option_flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,8 +262,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @return - z height is zero or not.
|
* @return - z height is zero or not.
|
||||||
* @see #getOptionFlags()
|
* @see #getOptionFlags()
|
||||||
*/
|
*/
|
||||||
public boolean getZeroHeight()
|
public boolean getZeroHeight() {
|
||||||
{
|
|
||||||
return zeroHeight.isSet(field_7_option_flags);
|
return zeroHeight.isSet(field_7_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,9 +271,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @return - f -true if they aren't compatible (damn not logic)
|
* @return - f -true if they aren't compatible (damn not logic)
|
||||||
* @see #getOptionFlags()
|
* @see #getOptionFlags()
|
||||||
*/
|
*/
|
||||||
|
public boolean getBadFontHeight() {
|
||||||
public boolean getBadFontHeight()
|
|
||||||
{
|
|
||||||
return badFontHeight.isSet(field_7_option_flags);
|
return badFontHeight.isSet(field_7_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,9 +280,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @return formatted or not
|
* @return formatted or not
|
||||||
* @see #getOptionFlags()
|
* @see #getOptionFlags()
|
||||||
*/
|
*/
|
||||||
|
public boolean getFormatted() {
|
||||||
public boolean getFormatted()
|
|
||||||
{
|
|
||||||
return formatted.isSet(field_7_option_flags);
|
return formatted.isSet(field_7_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,14 +291,11 @@ public final class RowRecord extends StandardRecord {
|
|||||||
* @see org.apache.poi.hssf.record.ExtendedFormatRecord
|
* @see org.apache.poi.hssf.record.ExtendedFormatRecord
|
||||||
* @return index to the XF record or bogus value (undefined) if isn't formatted
|
* @return index to the XF record or bogus value (undefined) if isn't formatted
|
||||||
*/
|
*/
|
||||||
|
public short getXFIndex() {
|
||||||
public short getXFIndex()
|
|
||||||
{
|
|
||||||
return field_8_xf_index;
|
return field_8_xf_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
sb.append("[ROW]\n");
|
sb.append("[ROW]\n");
|
||||||
@ -350,8 +332,7 @@ public final class RowRecord extends StandardRecord {
|
|||||||
return ENCODED_SIZE - 4;
|
return ENCODED_SIZE - 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getSid()
|
public short getSid() {
|
||||||
{
|
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,6 +1056,7 @@ public class HSSFCell implements Cell {
|
|||||||
* @return cell comment or <code>null</code> if not found
|
* @return cell comment or <code>null</code> if not found
|
||||||
*/
|
*/
|
||||||
protected static HSSFComment findCellComment(Sheet sheet, int row, int column){
|
protected static HSSFComment findCellComment(Sheet sheet, int row, int column){
|
||||||
|
// TODO - optimise this code by searching backwards, find NoteRecord first, quit if not found. Find one TXO by id
|
||||||
HSSFComment comment = null;
|
HSSFComment comment = null;
|
||||||
HashMap<Integer, TextObjectRecord> txshapesByShapeId = new HashMap<Integer, TextObjectRecord>();
|
HashMap<Integer, TextObjectRecord> txshapesByShapeId = new HashMap<Integer, TextObjectRecord>();
|
||||||
for (Iterator<RecordBase> it = sheet.getRecords().iterator(); it.hasNext(); ) {
|
for (Iterator<RecordBase> it = sheet.getRecords().iterator(); it.hasNext(); ) {
|
||||||
@ -1066,7 +1067,7 @@ public class HSSFCell implements Cell {
|
|||||||
TextObjectRecord txo = txshapesByShapeId.get(new Integer(note.getShapeId()));
|
TextObjectRecord txo = txshapesByShapeId.get(new Integer(note.getShapeId()));
|
||||||
comment = new HSSFComment(note, txo);
|
comment = new HSSFComment(note, txo);
|
||||||
comment.setRow(note.getRow());
|
comment.setRow(note.getRow());
|
||||||
comment.setColumn(note.getColumn());
|
comment.setColumn((short)note.getColumn());
|
||||||
comment.setAuthor(note.getAuthor());
|
comment.setAuthor(note.getAuthor());
|
||||||
comment.setVisible(note.getFlags() == NoteRecord.NOTE_VISIBLE);
|
comment.setVisible(note.getFlags() == NoteRecord.NOTE_VISIBLE);
|
||||||
comment.setString(txo.getStr());
|
comment.setString(txo.getStr());
|
||||||
@ -1074,7 +1075,7 @@ public class HSSFCell implements Cell {
|
|||||||
}
|
}
|
||||||
} else if (rec instanceof ObjRecord){
|
} else if (rec instanceof ObjRecord){
|
||||||
ObjRecord obj = (ObjRecord)rec;
|
ObjRecord obj = (ObjRecord)rec;
|
||||||
SubRecord sub = (SubRecord)obj.getSubRecords().get(0);
|
SubRecord sub = obj.getSubRecords().get(0);
|
||||||
if (sub instanceof CommonObjectDataSubRecord){
|
if (sub instanceof CommonObjectDataSubRecord){
|
||||||
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)sub;
|
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)sub;
|
||||||
if (cmo.getObjectType() == CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT){
|
if (cmo.getObjectType() == CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT){
|
||||||
|
@ -28,12 +28,23 @@ import org.apache.poi.ss.usermodel.RichTextString;
|
|||||||
*/
|
*/
|
||||||
public class HSSFComment extends HSSFTextbox implements Comment {
|
public class HSSFComment extends HSSFTextbox implements Comment {
|
||||||
|
|
||||||
private boolean visible;
|
/*
|
||||||
private short col, row;
|
* TODO - make HSSFComment more consistent when created vs read from file.
|
||||||
private String author;
|
* Currently HSSFComment has two main forms (corresponding to the two constructors). There
|
||||||
|
* are certain operations that only work on comment objects in one of the forms (e.g. deleting
|
||||||
|
* comments).
|
||||||
|
* POI is also deficient in its management of RowRecord fields firstCol and lastCol. Those
|
||||||
|
* fields are supposed to take comments into account, but POI does not do this yet (feb 2009).
|
||||||
|
* It seems like HSSFRow should manage a collection of local HSSFComments
|
||||||
|
*/
|
||||||
|
|
||||||
private NoteRecord note = null;
|
private boolean _visible;
|
||||||
private TextObjectRecord txo = null;
|
private int _row;
|
||||||
|
private int _col;
|
||||||
|
private String _author;
|
||||||
|
|
||||||
|
private NoteRecord _note;
|
||||||
|
private TextObjectRecord _txo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new comment with the given parent and anchor.
|
* Construct a new comment with the given parent and anchor.
|
||||||
@ -41,25 +52,23 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
* @param parent
|
* @param parent
|
||||||
* @param anchor defines position of this anchor in the sheet
|
* @param anchor defines position of this anchor in the sheet
|
||||||
*/
|
*/
|
||||||
public HSSFComment( HSSFShape parent, HSSFAnchor anchor )
|
public HSSFComment(HSSFShape parent, HSSFAnchor anchor) {
|
||||||
{
|
super(parent, anchor);
|
||||||
super( parent, anchor );
|
|
||||||
setShapeType(OBJECT_TYPE_COMMENT);
|
setShapeType(OBJECT_TYPE_COMMENT);
|
||||||
|
|
||||||
//default color for comments
|
//default color for comments
|
||||||
fillColor = 0x08000050;
|
fillColor = 0x08000050;
|
||||||
|
|
||||||
//by default comments are hidden
|
//by default comments are hidden
|
||||||
visible = false;
|
_visible = false;
|
||||||
|
|
||||||
author = "";
|
_author = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HSSFComment( NoteRecord note, TextObjectRecord txo )
|
protected HSSFComment(NoteRecord note, TextObjectRecord txo) {
|
||||||
{
|
this((HSSFShape) null, (HSSFAnchor) null);
|
||||||
this( (HSSFShape)null, (HSSFAnchor)null );
|
_txo = txo;
|
||||||
this.txo = txo;
|
_note = note;
|
||||||
this.note = note;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,8 +77,10 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
* @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
|
* @param visible <code>true</code> if the comment is visible, <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
public void setVisible(boolean visible){
|
public void setVisible(boolean visible){
|
||||||
if(note != null) note.setFlags(visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
|
if(_note != null) {
|
||||||
this.visible = visible;
|
_note.setFlags(visible ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
|
||||||
|
}
|
||||||
|
_visible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,8 +88,8 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @return <code>true</code> if the comment is visible, <code>false</code> otherwise
|
* @return <code>true</code> if the comment is visible, <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isVisible(){
|
public boolean isVisible() {
|
||||||
return this.visible;
|
return _visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,8 +97,8 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @return the 0-based row of the cell that contains the comment
|
* @return the 0-based row of the cell that contains the comment
|
||||||
*/
|
*/
|
||||||
public int getRow(){
|
public int getRow() {
|
||||||
return row;
|
return _row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +106,11 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @param row the 0-based row of the cell that contains the comment
|
* @param row the 0-based row of the cell that contains the comment
|
||||||
*/
|
*/
|
||||||
public void setRow(int row){
|
public void setRow(int row) {
|
||||||
if(note != null) note.setRow((short)row);
|
if(_note != null) {
|
||||||
this.row = (short)row;
|
_note.setRow(row);
|
||||||
|
}
|
||||||
|
_row = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,7 +119,7 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
* @return the 0-based column of the cell that contains the comment
|
* @return the 0-based column of the cell that contains the comment
|
||||||
*/
|
*/
|
||||||
public int getColumn(){
|
public int getColumn(){
|
||||||
return col;
|
return _col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,9 +127,11 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @param col the 0-based column of the cell that contains the comment
|
* @param col the 0-based column of the cell that contains the comment
|
||||||
*/
|
*/
|
||||||
public void setColumn(short col){
|
public void setColumn(short col) {
|
||||||
if(note != null) note.setColumn(col);
|
if(_note != null) {
|
||||||
this.col = col;
|
_note.setColumn(col);
|
||||||
|
}
|
||||||
|
_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,8 +139,8 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @return the name of the original author of the comment
|
* @return the name of the original author of the comment
|
||||||
*/
|
*/
|
||||||
public String getAuthor(){
|
public String getAuthor() {
|
||||||
return author;
|
return _author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,8 +149,8 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
* @param author the name of the original author of the comment
|
* @param author the name of the original author of the comment
|
||||||
*/
|
*/
|
||||||
public void setAuthor(String author){
|
public void setAuthor(String author){
|
||||||
if(note != null) note.setAuthor(author);
|
if(_note != null) _note.setAuthor(author);
|
||||||
this.author = author;
|
this._author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,13 +158,13 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
*
|
*
|
||||||
* @param string Sets the rich text string used by this object.
|
* @param string Sets the rich text string used by this object.
|
||||||
*/
|
*/
|
||||||
public void setString( RichTextString string ) {
|
public void setString(RichTextString string) {
|
||||||
HSSFRichTextString hstring = (HSSFRichTextString) string;
|
HSSFRichTextString hstring = (HSSFRichTextString) string;
|
||||||
//if font is not set we must set the default one
|
//if font is not set we must set the default one
|
||||||
if (hstring.numFormattingRuns() == 0) hstring.applyFont((short)0);
|
if (hstring.numFormattingRuns() == 0) hstring.applyFont((short)0);
|
||||||
|
|
||||||
if (txo != null) {
|
if (_txo != null) {
|
||||||
txo.setStr(hstring);
|
_txo.setStr(hstring);
|
||||||
}
|
}
|
||||||
super.setString(string);
|
super.setString(string);
|
||||||
}
|
}
|
||||||
@ -157,9 +172,13 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
|||||||
/**
|
/**
|
||||||
* Returns the underlying Note record
|
* Returns the underlying Note record
|
||||||
*/
|
*/
|
||||||
protected NoteRecord getNoteRecord() { return note; }
|
protected NoteRecord getNoteRecord() {
|
||||||
|
return _note;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the underlying Text record
|
* Returns the underlying Text record
|
||||||
*/
|
*/
|
||||||
protected TextObjectRecord getTextObjectRecord() { return txo; }
|
protected TextObjectRecord getTextObjectRecord() {
|
||||||
|
return _txo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,11 +30,11 @@ import org.apache.poi.ss.usermodel.Row;
|
|||||||
* High level representation of a row of a spreadsheet.
|
* High level representation of a row of a spreadsheet.
|
||||||
*
|
*
|
||||||
* Only rows that have cells should be added to a Sheet.
|
* 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 Andrew C. Oliver (acoliver at apache dot org)
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public final class HSSFRow implements Comparable, Row {
|
public final class HSSFRow implements Row {
|
||||||
|
|
||||||
// used for collections
|
// used for collections
|
||||||
public final static int INITIAL_CAPACITY = 5;
|
public final static int INITIAL_CAPACITY = 5;
|
||||||
@ -65,14 +65,8 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* @param rowNum the row number of this row (0 based)
|
* @param rowNum the row number of this row (0 based)
|
||||||
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
||||||
*/
|
*/
|
||||||
HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum)
|
HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum) {
|
||||||
{
|
this(book, sheet, new RowRecord(rowNum));
|
||||||
this.rowNum = rowNum;
|
|
||||||
this.book = book;
|
|
||||||
this.sheet = sheet;
|
|
||||||
row = new RowRecord(rowNum);
|
|
||||||
|
|
||||||
setRowNum(rowNum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,13 +78,15 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* @param record the low level api object this row should represent
|
* @param record the low level api object this row should represent
|
||||||
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
* @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int)
|
||||||
*/
|
*/
|
||||||
HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record)
|
HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) {
|
||||||
{
|
|
||||||
this.book = book;
|
this.book = book;
|
||||||
this.sheet = sheet;
|
this.sheet = sheet;
|
||||||
row = record;
|
row = record;
|
||||||
|
|
||||||
setRowNum(record.getRowNumber());
|
setRowNum(record.getRowNumber());
|
||||||
|
// Don't trust colIx boundaries as read by other apps
|
||||||
|
// set the RowRecord empty for the moment
|
||||||
|
record.setEmpty();
|
||||||
|
// subsequent calls to createCellFromRecord() will update the colIx boundaries properly
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,10 +132,10 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
*/
|
*/
|
||||||
public HSSFCell createCell(int columnIndex, int type)
|
public HSSFCell createCell(int columnIndex, int type)
|
||||||
{
|
{
|
||||||
short shortCellNum = (short)columnIndex;
|
short shortCellNum = (short)columnIndex;
|
||||||
if(columnIndex > 0x7FFF) {
|
if(columnIndex > 0x7FFF) {
|
||||||
shortCellNum = (short)(0xffff - columnIndex);
|
shortCellNum = (short)(0xffff - columnIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), shortCellNum, type);
|
HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), shortCellNum, type);
|
||||||
addCell(cell);
|
addCell(cell);
|
||||||
@ -172,12 +168,11 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
CellValueRecordInterface cval = cell.getCellValueRecord();
|
CellValueRecordInterface cval = cell.getCellValueRecord();
|
||||||
sheet.getSheet().removeValueRecord(getRowNum(), cval);
|
sheet.getSheet().removeValueRecord(getRowNum(), cval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getColumnIndex()+1 == row.getLastCol()) {
|
if (cell.getColumnIndex()+1 == row.getLastCol()) {
|
||||||
row.setLastCol((short) (findLastCell(row.getLastCol())+1));
|
row.setLastCol(calculateNewLastCellPlusOne(row.getLastCol()));
|
||||||
}
|
}
|
||||||
if (cell.getColumnIndex() == row.getFirstCol()) {
|
if (cell.getColumnIndex() == row.getFirstCol()) {
|
||||||
row.setFirstCol(findFirstCell(row.getFirstCol()));
|
row.setFirstCol(calculateNewFirstCell(row.getFirstCol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,27 +195,40 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* @param cell low level cell to create the high level representation from
|
* @param cell low level cell to create the high level representation from
|
||||||
* @return HSSFCell representing the low level record passed in
|
* @return HSSFCell representing the low level record passed in
|
||||||
*/
|
*/
|
||||||
protected HSSFCell createCellFromRecord(CellValueRecordInterface cell) {
|
HSSFCell createCellFromRecord(CellValueRecordInterface cell) {
|
||||||
HSSFCell hcell = new HSSFCell(book, sheet, cell);
|
HSSFCell hcell = new HSSFCell(book, sheet, cell);
|
||||||
|
|
||||||
addCell(hcell);
|
addCell(hcell);
|
||||||
|
int colIx = cell.getColumn();
|
||||||
|
if (row.isEmpty()) {
|
||||||
|
row.setFirstCol(colIx);
|
||||||
|
row.setLastCol(colIx + 1);
|
||||||
|
} else {
|
||||||
|
if (colIx < row.getFirstCol()) {
|
||||||
|
row.setFirstCol(colIx);
|
||||||
|
} else if (colIx > row.getLastCol()) {
|
||||||
|
row.setLastCol(colIx + 1);
|
||||||
|
} else {
|
||||||
|
// added cell is within first and last cells
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO - RowRecord column boundaries need to be updated for cell comments too
|
||||||
return hcell;
|
return hcell;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the row number of this row.
|
* set the row number of this row.
|
||||||
* @param rowNum the row number (0-based)
|
* @param rowIndex the row number (0-based)
|
||||||
* @throws IndexOutOfBoundsException if the row number is not within the range 0-65535.
|
* @throws IndexOutOfBoundsException if the row number is not within the range 0-65535.
|
||||||
*/
|
*/
|
||||||
public void setRowNum(int rowNum) {
|
public void setRowNum(int rowIndex) {
|
||||||
if ((rowNum < 0) || (rowNum > RowRecord.MAX_ROW_NUMBER)) {
|
if ((rowIndex < 0) || (rowIndex > RowRecord.MAX_ROW_NUMBER)) {
|
||||||
throw new IllegalArgumentException("Invalid row number (" + rowNum
|
throw new IllegalArgumentException("Invalid row number (" + rowIndex
|
||||||
+ ") outside allowable range (0.." + RowRecord.MAX_ROW_NUMBER + ")");
|
+ ") outside allowable range (0.." + RowRecord.MAX_ROW_NUMBER + ")");
|
||||||
}
|
}
|
||||||
this.rowNum = rowNum;
|
rowNum = rowIndex;
|
||||||
if (row != null)
|
if (row != null) {
|
||||||
{
|
row.setRowNumber(rowIndex); // used only for KEY comparison (HSSFRow)
|
||||||
row.setRowNumber(rowNum); // used only for KEY comparison (HSSFRow)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,11 +304,11 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
cells[column]=cell;
|
cells[column]=cell;
|
||||||
|
|
||||||
// fix up firstCol and lastCol indexes
|
// fix up firstCol and lastCol indexes
|
||||||
if (row.getFirstCol() == -1 || column < row.getFirstCol()) {
|
if (row.isEmpty() || column < row.getFirstCol()) {
|
||||||
row.setFirstCol((short)column);
|
row.setFirstCol((short)column);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row.getLastCol() == -1 || column >= row.getLastCol()) {
|
if (row.isEmpty() || column >= row.getLastCol()) {
|
||||||
row.setLastCol((short) (column+1)); // +1 -> for one past the last index
|
row.setLastCol((short) (column+1)); // +1 -> for one past the last index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,12 +319,14 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* you get a null.
|
* you get a null.
|
||||||
* This is the basic call, with no policies applied
|
* This is the basic call, with no policies applied
|
||||||
*
|
*
|
||||||
* @param cellnum 0 based column number
|
* @param cellIndex 0 based column number
|
||||||
* @return HSSFCell representing that column or null if undefined.
|
* @return HSSFCell representing that column or null if undefined.
|
||||||
*/
|
*/
|
||||||
private HSSFCell retrieveCell(int cellnum) {
|
private HSSFCell retrieveCell(int cellIndex) {
|
||||||
if(cellnum<0||cellnum>=cells.length) return null;
|
if(cellIndex<0||cellIndex>=cells.length) {
|
||||||
return cells[cellnum];
|
return null;
|
||||||
|
}
|
||||||
|
return cells[cellIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,12 +384,11 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* get the number of the first cell contained in this row.
|
* get the number of the first cell contained in this row.
|
||||||
* @return short representing the first logical cell in the row, or -1 if the row does not contain any cells.
|
* @return short representing the first logical cell in the row, or -1 if the row does not contain any cells.
|
||||||
*/
|
*/
|
||||||
public short getFirstCellNum()
|
public short getFirstCellNum() {
|
||||||
{
|
if (row.isEmpty()) {
|
||||||
if (getPhysicalNumberOfCells() == 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
else
|
}
|
||||||
return row.getFirstCol();
|
return (short) row.getFirstCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -402,10 +411,10 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* row does not contain any cells.
|
* row does not contain any cells.
|
||||||
*/
|
*/
|
||||||
public short getLastCellNum() {
|
public short getLastCellNum() {
|
||||||
if (getPhysicalNumberOfCells() == 0) {
|
if (row.isEmpty()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return row.getLastCol();
|
return (short) row.getLastCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -508,37 +517,37 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to refresh the "last cell" when the last cell is removed.
|
* used internally to refresh the "last cell plus one" when the last cell is removed.
|
||||||
|
* @return 0 when row contains no cells
|
||||||
*/
|
*/
|
||||||
|
private int calculateNewLastCellPlusOne(int lastcell) {
|
||||||
|
int cellIx = lastcell - 1;
|
||||||
|
HSSFCell r = retrieveCell(cellIx);
|
||||||
|
|
||||||
private short findLastCell(short lastcell)
|
while (r == null) {
|
||||||
{
|
if (cellIx < 0) {
|
||||||
short cellnum = (short) (lastcell - 1);
|
return 0;
|
||||||
HSSFCell r = getCell(cellnum);
|
}
|
||||||
|
r = retrieveCell(--cellIx);
|
||||||
while (r == null && cellnum >= 0)
|
|
||||||
{
|
|
||||||
r = getCell(--cellnum);
|
|
||||||
}
|
}
|
||||||
return cellnum;
|
return cellIx+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used internally to refresh the "first cell" when the first cell is removed.
|
* used internally to refresh the "first cell" when the first cell is removed.
|
||||||
|
* @return 0 when row contains no cells (also when first cell is occupied)
|
||||||
*/
|
*/
|
||||||
|
private int calculateNewFirstCell(int firstcell) {
|
||||||
|
int cellIx = firstcell + 1;
|
||||||
|
HSSFCell r = retrieveCell(cellIx);
|
||||||
|
|
||||||
private short findFirstCell(short firstcell)
|
while (r == null) {
|
||||||
{
|
if (cellIx <= cells.length) {
|
||||||
short cellnum = (short) (firstcell + 1);
|
return 0;
|
||||||
HSSFCell r = getCell(cellnum);
|
}
|
||||||
|
r = retrieveCell(++cellIx);
|
||||||
while (r == null && cellnum <= getLastCellNum())
|
|
||||||
{
|
|
||||||
r = getCell(++cellnum);
|
|
||||||
}
|
}
|
||||||
if (cellnum > getLastCellNum())
|
return cellIx;
|
||||||
return -1;
|
|
||||||
return cellnum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -547,7 +556,7 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* can get the formatting from {@link #getRowStyle()}
|
* can get the formatting from {@link #getRowStyle()}
|
||||||
*/
|
*/
|
||||||
public boolean isFormatted() {
|
public boolean isFormatted() {
|
||||||
return row.getFormatted();
|
return row.getFormatted();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the whole-row cell styles. Most rows won't
|
* Returns the whole-row cell styles. Most rows won't
|
||||||
@ -555,7 +564,7 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* {@link #isFormatted()} to check first.
|
* {@link #isFormatted()} to check first.
|
||||||
*/
|
*/
|
||||||
public HSSFCellStyle getRowStyle() {
|
public HSSFCellStyle getRowStyle() {
|
||||||
if(!isFormatted()) { return null; }
|
if(!isFormatted()) { return null; }
|
||||||
short styleIndex = row.getXFIndex();
|
short styleIndex = row.getXFIndex();
|
||||||
ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
|
ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
|
||||||
return new HSSFCellStyle(styleIndex, xf, book);
|
return new HSSFCellStyle(styleIndex, xf, book);
|
||||||
@ -564,8 +573,8 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* Applies a whole-row cell styling to the row.
|
* Applies a whole-row cell styling to the row.
|
||||||
*/
|
*/
|
||||||
public void setRowStyle(HSSFCellStyle style) {
|
public void setRowStyle(HSSFCellStyle style) {
|
||||||
row.setFormatted(true);
|
row.setFormatted(true);
|
||||||
row.setXFIndex(style.getIndex());
|
row.setXFIndex(style.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -576,7 +585,7 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* As this only ever works on physically defined cells,
|
* As this only ever works on physically defined cells,
|
||||||
* the {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} has no effect.
|
* the {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} has no effect.
|
||||||
*/
|
*/
|
||||||
public Iterator cellIterator()
|
public Iterator<Cell> cellIterator()
|
||||||
{
|
{
|
||||||
return new CellIterator();
|
return new CellIterator();
|
||||||
}
|
}
|
||||||
@ -591,8 +600,7 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
/**
|
/**
|
||||||
* An iterator over the (physical) cells in the row.
|
* An iterator over the (physical) cells in the row.
|
||||||
*/
|
*/
|
||||||
private class CellIterator implements Iterator
|
private class CellIterator implements Iterator<Cell> {
|
||||||
{
|
|
||||||
int thisId=-1;
|
int thisId=-1;
|
||||||
int nextId=-1;
|
int nextId=-1;
|
||||||
|
|
||||||
@ -605,7 +613,7 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
return nextId<cells.length;
|
return nextId<cells.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object next() {
|
public Cell next() {
|
||||||
if (!hasNext())
|
if (!hasNext())
|
||||||
throw new NoSuchElementException("At last element");
|
throw new NoSuchElementException("At last element");
|
||||||
HSSFCell cell=cells[nextId];
|
HSSFCell cell=cells[nextId];
|
||||||
|
@ -37,6 +37,7 @@ import org.apache.poi.hssf.record.CellValueRecordInterface;
|
|||||||
import org.apache.poi.hssf.record.DVRecord;
|
import org.apache.poi.hssf.record.DVRecord;
|
||||||
import org.apache.poi.hssf.record.EscherAggregate;
|
import org.apache.poi.hssf.record.EscherAggregate;
|
||||||
import org.apache.poi.hssf.record.ExtendedFormatRecord;
|
import org.apache.poi.hssf.record.ExtendedFormatRecord;
|
||||||
|
import org.apache.poi.hssf.record.NoteRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.record.RowRecord;
|
import org.apache.poi.hssf.record.RowRecord;
|
||||||
import org.apache.poi.hssf.record.SCLRecord;
|
import org.apache.poi.hssf.record.SCLRecord;
|
||||||
@ -45,10 +46,11 @@ import org.apache.poi.hssf.record.WindowTwoRecord;
|
|||||||
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
||||||
import org.apache.poi.hssf.record.formula.FormulaShifter;
|
import org.apache.poi.hssf.record.formula.FormulaShifter;
|
||||||
import org.apache.poi.hssf.util.PaneInformation;
|
import org.apache.poi.hssf.util.PaneInformation;
|
||||||
|
import org.apache.poi.hssf.util.Region;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.hssf.util.Region;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
|
|
||||||
@ -1160,6 +1162,12 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
s = endRow;
|
s = endRow;
|
||||||
inc = -1;
|
inc = -1;
|
||||||
}
|
}
|
||||||
|
NoteRecord[] noteRecs;
|
||||||
|
if (moveComments) {
|
||||||
|
noteRecs = sheet.getNoteRecords();
|
||||||
|
} else {
|
||||||
|
noteRecs = NoteRecord.EMPTY_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
shiftMerged(startRow, endRow, n, true);
|
shiftMerged(startRow, endRow, n, true);
|
||||||
sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);
|
sheet.getPageSettings().shiftRowBreaks(startRow, endRow, n);
|
||||||
@ -1182,12 +1190,6 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
// be done for the now empty destination row
|
// be done for the now empty destination row
|
||||||
if (row == null) continue; // Nothing to do for this row
|
if (row == null) continue; // Nothing to do for this row
|
||||||
|
|
||||||
// Fetch the first and last columns of the
|
|
||||||
// row now, so we still have them to hand
|
|
||||||
// once we start removing cells
|
|
||||||
short firstCol = row.getFirstCellNum();
|
|
||||||
short lastCol = row.getLastCellNum();
|
|
||||||
|
|
||||||
// Fix up row heights if required
|
// Fix up row heights if required
|
||||||
if (copyRowHeight) {
|
if (copyRowHeight) {
|
||||||
row2Replace.setHeight(row.getHeight());
|
row2Replace.setHeight(row.getHeight());
|
||||||
@ -1198,7 +1200,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
|
|
||||||
// Copy each cell from the source row to
|
// Copy each cell from the source row to
|
||||||
// the destination row
|
// the destination row
|
||||||
for(Iterator cells = row.cellIterator(); cells.hasNext(); ) {
|
for(Iterator<Cell> cells = row.cellIterator(); cells.hasNext(); ) {
|
||||||
HSSFCell cell = (HSSFCell)cells.next();
|
HSSFCell cell = (HSSFCell)cells.next();
|
||||||
row.removeCell( cell );
|
row.removeCell( cell );
|
||||||
CellValueRecordInterface cellRecord = cell.getCellValueRecord();
|
CellValueRecordInterface cellRecord = cell.getCellValueRecord();
|
||||||
@ -1219,8 +1221,13 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||||||
// destination row. Note that comments can
|
// destination row. Note that comments can
|
||||||
// exist for cells which are null
|
// exist for cells which are null
|
||||||
if(moveComments) {
|
if(moveComments) {
|
||||||
for( short col = firstCol; col <= lastCol; col++ ) {
|
// This code would get simpler if NoteRecords could be organised by HSSFRow.
|
||||||
HSSFComment comment = getCellComment(rowNum, col);
|
for(int i=noteRecs.length-1; i>=0; i--) {
|
||||||
|
NoteRecord nr = noteRecs[i];
|
||||||
|
if (nr.getRow() != rowNum) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
HSSFComment comment = getCellComment(rowNum, nr.getColumn());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
comment.setRow(rowNum + n);
|
comment.setRow(rowNum + n);
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,11 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.io.*;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ public final class TestHSSFComment extends TestCase {
|
|||||||
String commentText = "We can set comments in POI";
|
String commentText = "We can set comments in POI";
|
||||||
String commentAuthor = "Apache Software Foundation";
|
String commentAuthor = "Apache Software Foundation";
|
||||||
int cellRow = 3;
|
int cellRow = 3;
|
||||||
short cellColumn = 1;
|
int cellColumn = 1;
|
||||||
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
|
||||||
@ -55,6 +57,10 @@ public final class TestHSSFComment extends TestCase {
|
|||||||
comment.setString(string1);
|
comment.setString(string1);
|
||||||
comment.setAuthor(commentAuthor);
|
comment.setAuthor(commentAuthor);
|
||||||
cell.setCellComment(comment);
|
cell.setCellComment(comment);
|
||||||
|
if (false) {
|
||||||
|
// TODO - the following line should break this test, but it doesn't
|
||||||
|
cell.removeCellComment();
|
||||||
|
}
|
||||||
|
|
||||||
//verify our settings
|
//verify our settings
|
||||||
assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
|
assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType());
|
||||||
|
@ -17,9 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
|
import org.apache.poi.hssf.record.BlankRecord;
|
||||||
|
import org.apache.poi.hssf.record.RowRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test HSSFRow is okay.
|
* Test HSSFRow is okay.
|
||||||
@ -48,6 +51,32 @@ public final class TestHSSFRow extends TestCase {
|
|||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
assertEquals(4, row.getLastCellNum());
|
assertEquals(4, row.getLastCellNum());
|
||||||
}
|
}
|
||||||
|
public void testLastAndFirstColumns_bug46654() {
|
||||||
|
int ROW_IX = 10;
|
||||||
|
int COL_IX = 3;
|
||||||
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
|
HSSFSheet sheet = workbook.createSheet("Sheet1");
|
||||||
|
RowRecord rowRec = new RowRecord(ROW_IX);
|
||||||
|
rowRec.setFirstCol((short)2);
|
||||||
|
rowRec.setLastCol((short)5);
|
||||||
|
|
||||||
|
BlankRecord br = new BlankRecord();
|
||||||
|
br.setRow(ROW_IX);
|
||||||
|
br.setColumn((short)COL_IX);
|
||||||
|
|
||||||
|
sheet.getSheet().addValueRecord(ROW_IX, br);
|
||||||
|
HSSFRow row = new HSSFRow(workbook, sheet, rowRec);
|
||||||
|
HSSFCell cell = row.createCellFromRecord(br);
|
||||||
|
|
||||||
|
if (row.getFirstCellNum() == 2 && row.getLastCellNum() == 5) {
|
||||||
|
throw new AssertionFailedError("Identified bug 46654a");
|
||||||
|
}
|
||||||
|
assertEquals(COL_IX, row.getFirstCellNum());
|
||||||
|
assertEquals(COL_IX + 1, row.getLastCellNum());
|
||||||
|
row.removeCell(cell);
|
||||||
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
|
assertEquals(-1, row.getLastCellNum());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
|
* Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
|
||||||
@ -208,7 +237,7 @@ public final class TestHSSFRow extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Tests for the missing/blank cell policy stuff
|
* Tests for the missing/blank cell policy stuff
|
||||||
*/
|
*/
|
||||||
public void testGetCellPolicy() throws Exception {
|
public void testGetCellPolicy() {
|
||||||
HSSFWorkbook book = new HSSFWorkbook();
|
HSSFWorkbook book = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = book.createSheet("test");
|
HSSFSheet sheet = book.createSheet("test");
|
||||||
HSSFRow row = sheet.createRow(0);
|
HSSFRow row = sheet.createRow(0);
|
||||||
@ -300,5 +329,4 @@ public final class TestHSSFRow extends TestCase {
|
|||||||
row2 = sheet.getRow(1);
|
row2 = sheet.getRow(1);
|
||||||
assertEquals(400, row2.getHeight());
|
assertEquals(400, row2.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user