1 19 20 package jxl.biff.formula; 21 22 import jxl.Cell; 23 import jxl.biff.IntegerHelper; 24 import jxl.biff.CellReferenceHelper; 25 26 29 class SharedFormulaCellReference extends Operand implements ParsedThing 30 { 31 34 private boolean columnRelative; 35 36 39 private boolean rowRelative; 40 41 44 private int column; 45 46 49 private int row; 50 51 55 private Cell relativeTo; 56 57 62 public SharedFormulaCellReference(Cell rt) 63 { 64 relativeTo = rt; 65 } 66 67 74 public int read(byte[] data, int pos) 75 { 76 row = IntegerHelper.getShort(data[pos], data[pos+1]); 79 80 int columnMask = IntegerHelper.getInt(data[pos+2], data[pos+3]); 81 82 column = (byte) (columnMask & 0xff); 83 columnRelative = ((columnMask & 0x4000) != 0); 84 rowRelative = ((columnMask & 0x8000) != 0); 85 86 if (columnRelative) 87 { 88 column = relativeTo.getColumn() + column; 89 } 90 91 if (rowRelative) 92 { 93 row = relativeTo.getRow() + row; 94 } 95 96 return 4; 97 } 98 99 public int getColumn() 100 { 101 return column; 102 } 103 104 public int getRow() 105 { 106 return row; 107 } 108 109 public void getString(StringBuffer buf) 110 { 111 CellReferenceHelper.getCellReference(column, row, buf); 112 } 113 114 119 byte[] getBytes() 120 { 121 byte[] data = new byte[5]; 122 data[0] = Token.REF.getCode(); 123 124 IntegerHelper.getTwoBytes(row, data, 1); 125 126 int columnMask = column; 127 128 if (columnRelative) 129 { 130 columnMask |= 0x4000; 131 } 132 133 if (rowRelative) 134 { 135 columnMask |= 0x8000; 136 } 137 138 IntegerHelper.getTwoBytes(columnMask, data, 3); 139 140 return data; 141 } 142 } 143 144 145 146 147 148 149 150 151 152 | Popular Tags |