1 16 17 package org.apache.poi.hssf.record.formula; 18 19 import org.apache.poi.util.LittleEndian; 20 import org.apache.poi.hssf.util.RangeAddress; 21 import org.apache.poi.hssf.util.AreaReference; 22 import org.apache.poi.hssf.util.CellReference; 23 import org.apache.poi.hssf.util.SheetReferences; 24 25 import org.apache.poi.hssf.model.Workbook; 26 import org.apache.poi.util.BitField; 27 28 37 38 public class Area3DPtg extends Ptg 39 { 40 public final static byte sid = 0x3b; 41 private final static int SIZE = 11; private short field_1_index_extern_sheet; 43 private short field_2_first_row; 44 private short field_3_last_row; 45 private short field_4_first_column; 46 private short field_5_last_column; 47 48 private BitField rowRelative = new BitField( 0x8000 ); 49 private BitField colRelative = new BitField( 0x4000 ); 50 51 52 public Area3DPtg() 53 { 54 } 55 56 public Area3DPtg( String arearef, short externIdx ) 57 { 58 setArea(arearef); 59 setExternSheetIndex( externIdx ); 60 61 } 62 63 public Area3DPtg( byte[] data, int offset ) 64 { 65 offset++; 66 field_1_index_extern_sheet = LittleEndian.getShort( data, 0 + offset ); 67 field_2_first_row = LittleEndian.getShort( data, 2 + offset ); 68 field_3_last_row = LittleEndian.getShort( data, 4 + offset ); 69 field_4_first_column = LittleEndian.getShort( data, 6 + offset ); 70 field_5_last_column = LittleEndian.getShort( data, 8 + offset ); 71 } 72 73 public String toString() 74 { 75 StringBuffer buffer = new StringBuffer (); 76 77 buffer.append( "AreaPtg\n" ); 78 buffer.append( "Index to Extern Sheet = " + getExternSheetIndex() ).append( "\n" ); 79 buffer.append( "firstRow = " + getFirstRow() ).append( "\n" ); 80 buffer.append( "lastRow = " + getLastRow() ).append( "\n" ); 81 buffer.append( "firstCol = " + getFirstColumn() ).append( "\n" ); 82 buffer.append( "lastCol = " + getLastColumn() ).append( "\n" ); 83 buffer.append( "firstColRel= " 84 + isFirstRowRelative() ).append( "\n" ); 85 buffer.append( "lastColRowRel = " 86 + isLastRowRelative() ).append( "\n" ); 87 buffer.append( "firstColRel = " + isFirstColRelative() ).append( "\n" ); 88 buffer.append( "lastColRel = " + isLastColRelative() ).append( "\n" ); 89 return buffer.toString(); 90 } 91 92 public void writeBytes( byte[] array, int offset ) 93 { 94 array[0 + offset] = (byte) ( sid + ptgClass ); 95 LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() ); 96 LittleEndian.putShort( array, 3 + offset, getFirstRow() ); 97 LittleEndian.putShort( array, 5 + offset, getLastRow() ); 98 LittleEndian.putShort( array, 7 + offset, getFirstColumnRaw() ); 99 LittleEndian.putShort( array, 9 + offset, getLastColumnRaw() ); 100 } 101 102 public int getSize() 103 { 104 return SIZE; 105 } 106 107 public short getExternSheetIndex() 108 { 109 return field_1_index_extern_sheet; 110 } 111 112 public void setExternSheetIndex( short index ) 113 { 114 field_1_index_extern_sheet = index; 115 } 116 117 public short getFirstRow() 118 { 119 return field_2_first_row; 120 } 121 122 public void setFirstRow( short row ) 123 { 124 field_2_first_row = row; 125 } 126 127 public short getLastRow() 128 { 129 return field_3_last_row; 130 } 131 132 public void setLastRow( short row ) 133 { 134 field_3_last_row = row; 135 } 136 137 public short getFirstColumn() 138 { 139 return (short) ( field_4_first_column & 0xFF ); 140 } 141 142 public short getFirstColumnRaw() 143 { 144 return field_4_first_column; 145 } 146 147 public boolean isFirstRowRelative() 148 { 149 return rowRelative.isSet( field_4_first_column ); 150 } 151 152 public boolean isFirstColRelative() 153 { 154 return colRelative.isSet( field_4_first_column ); 155 } 156 157 public void setFirstColumn( short column ) 158 { 159 field_4_first_column &= 0xFF00; 160 field_4_first_column |= column & 0xFF; 161 } 162 163 public void setFirstColumnRaw( short column ) 164 { 165 field_4_first_column = column; 166 } 167 168 public short getLastColumn() 169 { 170 return (short) ( field_5_last_column & 0xFF ); 171 } 172 173 public short getLastColumnRaw() 174 { 175 return field_5_last_column; 176 } 177 178 public boolean isLastRowRelative() 179 { 180 return rowRelative.isSet( field_5_last_column ); 181 } 182 183 public boolean isLastColRelative() 184 { 185 return colRelative.isSet( field_5_last_column ); 186 } 187 188 public void setLastColumn( short column ) 189 { 190 field_5_last_column &= 0xFF00; 191 field_5_last_column |= column & 0xFF; 192 } 193 194 public void setLastColumnRaw( short column ) 195 { 196 field_5_last_column = column; 197 } 198 199 203 public void setFirstRowRelative( boolean rel ) 204 { 205 field_4_first_column = rowRelative.setShortBoolean( field_4_first_column, rel ); 206 } 207 208 211 public void setFirstColRelative( boolean rel ) 212 { 213 field_4_first_column = colRelative.setShortBoolean( field_4_first_column, rel ); 214 } 215 216 220 public void setLastRowRelative( boolean rel ) 221 { 222 field_5_last_column = rowRelative.setShortBoolean( field_5_last_column, rel ); 223 } 224 225 228 public void setLastColRelative( boolean rel ) 229 { 230 field_5_last_column = colRelative.setShortBoolean( field_5_last_column, rel ); 231 } 232 233 234 240 241 public void setArea( String ref ) 242 { 243 AreaReference ar = new AreaReference( ref ); 244 245 setFirstRow( (short) ar.getCells()[0].getRow() ); 246 setFirstColumn( (short) ar.getCells()[0].getCol() ); 247 setLastRow( (short) ar.getCells()[1].getRow() ); 248 setLastColumn( (short) ar.getCells()[1].getCol() ); 249 setFirstColRelative( !ar.getCells()[0].isColAbsolute() ); 250 setLastColRelative( !ar.getCells()[1].isColAbsolute() ); 251 setFirstRowRelative( !ar.getCells()[0].isRowAbsolute() ); 252 setLastRowRelative( !ar.getCells()[1].isRowAbsolute() ); 253 254 } 255 256 public String toFormulaString(Workbook book) 257 { 258 SheetReferences refs = book == null ? null : book.getSheetReferences(); 259 StringBuffer retval = new StringBuffer (); 260 if ( refs != null ) 261 { 262 retval.append( refs.getSheetName( this.field_1_index_extern_sheet ) ); 263 retval.append( '!' ); 264 } 265 retval.append( ( new CellReference( getFirstRow(), getFirstColumn(), !isFirstRowRelative(), !isFirstColRelative() ) ).toString() ); 266 retval.append( ':' ); 267 retval.append( ( new CellReference( getLastRow(), getLastColumn(), !isLastRowRelative(), !isLastColRelative() ) ).toString() ); 268 return retval.toString(); 269 } 270 271 public byte getDefaultOperandClass() 272 { 273 return Ptg.CLASS_REF; 274 } 275 276 public Object clone() 277 { 278 Area3DPtg ptg = new Area3DPtg(); 279 ptg.field_1_index_extern_sheet = field_1_index_extern_sheet; 280 ptg.field_2_first_row = field_2_first_row; 281 ptg.field_3_last_row = field_3_last_row; 282 ptg.field_4_first_column = field_4_first_column; 283 ptg.field_5_last_column = field_5_last_column; 284 ptg.setClass(ptgClass); 285 return ptg; 286 } 287 288 289 public boolean equals( Object o ) 290 { 291 if ( this == o ) return true; 292 if ( !( o instanceof Area3DPtg ) ) return false; 293 294 final Area3DPtg area3DPtg = (Area3DPtg) o; 295 296 if ( field_1_index_extern_sheet != area3DPtg.field_1_index_extern_sheet ) return false; 297 if ( field_2_first_row != area3DPtg.field_2_first_row ) return false; 298 if ( field_3_last_row != area3DPtg.field_3_last_row ) return false; 299 if ( field_4_first_column != area3DPtg.field_4_first_column ) return false; 300 if ( field_5_last_column != area3DPtg.field_5_last_column ) return false; 301 302 return true; 303 } 304 305 public int hashCode() 306 { 307 int result; 308 result = (int) field_1_index_extern_sheet; 309 result = 29 * result + (int) field_2_first_row; 310 result = 29 * result + (int) field_3_last_row; 311 result = 29 * result + (int) field_4_first_column; 312 result = 29 * result + (int) field_5_last_column; 313 return result; 314 } 315 316 317 } 318 | Popular Tags |