1 16 17 18 package org.apache.poi.hssf.record.formula; 19 20 import org.apache.poi.util.LittleEndian; 21 22 import org.apache.poi.hssf.util.RangeAddress; 23 import org.apache.poi.hssf.util.CellReference; 24 import org.apache.poi.hssf.util.SheetReferences; 25 import org.apache.poi.hssf.model.Workbook; 26 import org.apache.poi.util.BitField; 27 import org.apache.poi.hssf.model.Workbook; 28 29 37 38 public class Ref3DPtg extends Ptg { 39 public final static byte sid = 0x3a; 40 private final static int SIZE = 7; private short field_1_index_extern_sheet; 42 private short field_2_row; 43 private short field_3_column; 44 private BitField rowRelative = new BitField(0x8000); 45 private BitField colRelative = new BitField(0x4000); 46 47 48 public Ref3DPtg() {} 49 50 public Ref3DPtg(byte[] data, int offset) { 51 offset++; 52 field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset); 53 field_2_row = LittleEndian.getShort(data, 2 + offset); 54 field_3_column = LittleEndian.getShort(data, 4 + offset); 55 } 56 57 public Ref3DPtg(String cellref, short externIdx ) { 58 CellReference c= new CellReference(cellref); 59 setRow((short) c.getRow()); 60 setColumn((short) c.getCol()); 61 setColRelative(!c.isColAbsolute()); 62 setRowRelative(!c.isRowAbsolute()); 63 setExternSheetIndex(externIdx); 64 } 65 66 public String toString() { 67 StringBuffer buffer = new StringBuffer (); 68 69 buffer.append("Ref3dPtg\n"); 70 buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n"); 71 buffer.append("Row = " + getRow()).append("\n"); 72 buffer.append("Col = " + getColumn()).append("\n"); 73 buffer.append("ColRowRel= " 74 + isRowRelative()).append("\n"); 75 buffer.append("ColRel = " + isColRelative()).append("\n"); 76 return buffer.toString(); 77 } 78 79 public void writeBytes(byte [] array, int offset) { 80 array[ 0 + offset ] = (byte) (sid + ptgClass); 81 LittleEndian.putShort(array, 1 + offset , getExternSheetIndex()); 82 LittleEndian.putShort(array, 3 + offset , getRow()); 83 LittleEndian.putShort(array, 5 + offset , getColumnRaw()); 84 } 85 86 public int getSize() { 87 return SIZE; 88 } 89 90 public short getExternSheetIndex(){ 91 return field_1_index_extern_sheet; 92 } 93 94 public void setExternSheetIndex(short index){ 95 field_1_index_extern_sheet = index; 96 } 97 98 public short getRow() { 99 return field_2_row; 100 } 101 102 public void setRow(short row) { 103 field_2_row = row; 104 } 105 106 public short getColumn() { 107 return ( short ) (field_3_column & 0xFF); 108 } 109 110 public short getColumnRaw() { 111 return field_3_column; 112 } 113 114 public boolean isRowRelative() 115 { 116 return rowRelative.isSet(field_3_column); 117 } 118 119 public void setRowRelative(boolean rel) { 120 field_3_column=rowRelative.setShortBoolean(field_3_column,rel); 121 } 122 123 public boolean isColRelative() 124 { 125 return colRelative.isSet(field_3_column); 126 } 127 128 public void setColRelative(boolean rel) { 129 field_3_column=colRelative.setShortBoolean(field_3_column,rel); 130 } 131 public void setColumn(short column) { 132 field_3_column &= 0xFF00; 133 field_3_column |= column & 0xFF; 134 } 135 136 public void setColumnRaw(short column) { 137 field_3_column = column; 138 } 139 140 147 148 public void setArea(String ref){ 149 RangeAddress ra = new RangeAddress(ref); 150 151 String from = ra.getFromCell(); 152 153 setColumn((short) (ra.getXPosition(from) -1)); 154 setRow((short) (ra.getYPosition(from) -1)); 155 156 } 157 158 public String toFormulaString(Workbook book) { 159 StringBuffer retval = new StringBuffer (); 160 SheetReferences refs = book == null ? null : book.getSheetReferences(); 161 if (refs != null) { 162 retval.append(refs.getSheetName((int)this.field_1_index_extern_sheet)); 163 retval.append('!'); 164 } 165 retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString()); 166 return retval.toString(); 167 } 168 169 public byte getDefaultOperandClass() {return Ptg.CLASS_REF;} 170 171 public Object clone() { 172 Ref3DPtg ptg = new Ref3DPtg(); 173 ptg.field_1_index_extern_sheet = field_1_index_extern_sheet; 174 ptg.field_2_row = field_2_row; 175 ptg.field_3_column = field_3_column; 176 ptg.setClass(ptgClass); 177 return ptg; 178 } 179 180 } 181 | Popular Tags |