1 16 17 18 package org.apache.poi.hssf.record.formula; 19 20 import org.apache.poi.util.LittleEndian; 21 import org.apache.poi.util.BitField; 22 23 import org.apache.poi.hssf.util.AreaReference; 24 import org.apache.poi.hssf.util.CellReference; 25 import org.apache.poi.hssf.model.Workbook; 26 27 32 33 public class AreaPtg 34 extends Ptg 35 { 36 public final static short sid = 0x25; 37 private final static int SIZE = 9; 38 private short field_1_first_row; 39 private short field_2_last_row; 40 private short field_3_first_column; 41 private short field_4_last_column; 42 43 private BitField rowRelative = new BitField(0x8000); 44 private BitField colRelative = new BitField(0x4000); 45 private BitField column = new BitField(0x3FFF); 46 47 private AreaPtg() { 48 } 50 51 public AreaPtg(String arearef) { 52 AreaReference ar = new AreaReference(arearef); 53 setFirstRow((short)ar.getCells()[0].getRow()); 54 setFirstColumn((short)ar.getCells()[0].getCol()); 55 setLastRow((short)ar.getCells()[1].getRow()); 56 setLastColumn((short)ar.getCells()[1].getCol()); 57 setFirstColRelative(!ar.getCells()[0].isColAbsolute()); 58 setLastColRelative(!ar.getCells()[1].isColAbsolute()); 59 setFirstRowRelative(!ar.getCells()[0].isRowAbsolute()); 60 setLastRowRelative(!ar.getCells()[1].isRowAbsolute()); 61 62 } 63 64 public AreaPtg(byte [] data, int offset) 65 { 66 offset++; 67 field_1_first_row = LittleEndian.getShort(data, 0 + offset); 68 field_2_last_row = LittleEndian.getShort(data, 2 + offset); 69 field_3_first_column = LittleEndian.getShort(data, 4 + offset); 70 field_4_last_column = LittleEndian.getShort(data, 6 + offset); 71 } 73 74 public String toString() 75 { 76 StringBuffer buffer = new StringBuffer (); 77 78 buffer.append("AreaPtg\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("firstColRowRel= " 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 array[offset] = (byte) (sid + ptgClass); 94 LittleEndian.putShort(array,offset+1,field_1_first_row); 95 LittleEndian.putShort(array,offset+3,field_2_last_row); 96 LittleEndian.putShort(array,offset+5,field_3_first_column); 97 LittleEndian.putShort(array,offset+7,field_4_last_column); 98 } 99 100 public int getSize() 101 { 102 return SIZE; 103 } 104 105 108 public short getFirstRow() 109 { 110 return field_1_first_row; 111 } 112 113 117 public void setFirstRow(short row) 118 { 119 field_1_first_row = row; 120 } 121 122 125 public short getLastRow() 126 { 127 return field_2_last_row; 128 } 129 130 133 public void setLastRow(short row) 134 { 135 field_2_last_row = row; 136 } 137 138 141 public short getFirstColumn() 142 { 143 return column.getShortValue(field_3_first_column); 144 } 145 146 149 public short getFirstColumnRaw() 150 { 151 return field_3_first_column; 152 } 153 154 157 public boolean isFirstRowRelative() 158 { 159 return rowRelative.isSet(field_3_first_column); 160 } 161 162 166 public void setFirstRowRelative(boolean rel) { 167 field_3_first_column=rowRelative.setShortBoolean(field_3_first_column,rel); 168 } 169 170 173 public boolean isFirstColRelative() 174 { 175 return colRelative.isSet(field_3_first_column); 176 } 177 178 181 public void setFirstColRelative(boolean rel) { 182 field_3_first_column=colRelative.setShortBoolean(field_3_first_column,rel); 183 } 184 185 188 public void setFirstColumn(short column) 189 { 190 field_3_first_column = column; } 192 193 196 public void setFirstColumnRaw(short column) 197 { 198 field_3_first_column = column; 199 } 200 201 204 public short getLastColumn() 205 { 206 return column.getShortValue(field_4_last_column); 207 } 208 209 212 public short getLastColumnRaw() 213 { 214 return field_4_last_column; 215 } 216 217 220 public boolean isLastRowRelative() 221 { 222 return rowRelative.isSet(field_4_last_column); 223 } 224 225 230 public void setLastRowRelative(boolean rel) { 231 field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel); 232 } 233 234 237 public boolean isLastColRelative() 238 { 239 return colRelative.isSet(field_4_last_column); 240 } 241 242 245 public void setLastColRelative(boolean rel) { 246 field_4_last_column=colRelative.setShortBoolean(field_4_last_column,rel); 247 } 248 249 250 253 public void setLastColumn(short column) 254 { 255 field_4_last_column = column; } 257 258 261 public void setLastColumnRaw(short column) 262 { 263 field_4_last_column = column; 264 } 265 266 public String toFormulaString(Workbook book) 267 { 268 return (new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString() + ":" + 269 (new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString(); 270 } 271 272 public byte getDefaultOperandClass() { 273 return Ptg.CLASS_REF; 274 } 275 276 public Object clone() { 277 AreaPtg ptg = new AreaPtg(); 278 ptg.field_1_first_row = field_1_first_row; 279 ptg.field_2_last_row = field_2_last_row; 280 ptg.field_3_first_column = field_3_first_column; 281 ptg.field_4_last_column = field_4_last_column; 282 ptg.setClass(ptgClass); 283 return ptg; 284 } 285 286 } 287 | Popular Tags |