1 16 17 package org.apache.poi.hssf.record.formula; 18 19 import org.apache.poi.util.LittleEndian; 20 import org.apache.poi.util.BitField; 21 22 import org.apache.poi.hssf.util.CellReference; 23 import org.apache.poi.hssf.model.Workbook; 24 25 30 31 public class ReferencePtg extends Ptg 32 { 33 private final static int SIZE = 5; 34 public final static byte sid = 0x24; 35 private short field_1_row; 37 private short field_2_col; 38 private BitField rowRelative = new BitField(0x8000); 39 private BitField colRelative = new BitField(0x4000); 40 41 private ReferencePtg() { 42 } 44 45 49 public ReferencePtg(String cellref) { 50 CellReference c= new CellReference(cellref); 51 setRow((short) c.getRow()); 52 setColumn((short) c.getCol()); 53 setColRelative(!c.isColAbsolute()); 54 setRowRelative(!c.isRowAbsolute()); 55 } 56 57 58 59 public ReferencePtg(byte[] data, int offset) 60 { 61 offset++; field_1_row = LittleEndian.getShort(data, offset + 0); 63 field_2_col = LittleEndian.getShort(data, offset + 2); 64 65 } 66 67 public String toString() 68 { 69 StringBuffer buffer = new StringBuffer ("[ValueReferencePtg]\n"); 70 71 buffer.append("row = ").append(getRow()).append("\n"); 72 buffer.append("col = ").append(getColumnRaw()).append("\n"); 73 buffer.append("rowrelative = ").append(isRowRelative()).append("\n"); 74 buffer.append("colrelative = ").append(isColRelative()).append("\n"); 75 return buffer.toString(); 76 } 77 78 public void writeBytes(byte [] array, int offset) 79 { 80 array[offset] = (byte) (sid + ptgClass); 81 LittleEndian.putShort(array,offset+1,field_1_row); 82 LittleEndian.putShort(array,offset+3,field_2_col); 83 } 84 85 public void setRow(short row) 86 { 87 field_1_row = row; 88 } 89 90 public short getRow() 91 { 92 return field_1_row; 93 } 94 95 public boolean isRowRelative() 96 { 97 return rowRelative.isSet(field_2_col); 98 } 99 100 public void setRowRelative(boolean rel) { 101 field_2_col=rowRelative.setShortBoolean(field_2_col,rel); 102 } 103 104 public boolean isColRelative() 105 { 106 return colRelative.isSet(field_2_col); 107 } 108 109 public void setColRelative(boolean rel) { 110 field_2_col=colRelative.setShortBoolean(field_2_col,rel); 111 } 112 113 public void setColumnRaw(short col) 114 { 115 field_2_col = col; 116 } 117 118 public short getColumnRaw() 119 { 120 return field_2_col; 121 } 122 123 public void setColumn(short col) 124 { 125 field_2_col = col; } 127 128 public short getColumn() 129 { 130 return rowRelative.setShortBoolean(colRelative.setShortBoolean(field_2_col,false),false); 131 } 132 133 public int getSize() 134 { 135 return SIZE; 136 } 137 138 public String toFormulaString(Workbook book) 139 { 140 return (new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString(); 142 } 143 144 public byte getDefaultOperandClass() { 145 return Ptg.CLASS_REF; 146 } 147 148 public Object clone() { 149 ReferencePtg ptg = new ReferencePtg(); 150 ptg.field_1_row = field_1_row; 151 ptg.field_2_col = field_2_col; 152 ptg.setClass(ptgClass); 153 return ptg; 154 } 155 } 156 | Popular Tags |