1 19 20 package jxl.biff.formula; 21 22 import common.Logger; 23 24 import jxl.Cell; 25 import jxl.biff.IntegerHelper; 26 import jxl.biff.CellReferenceHelper; 27 28 31 class CellReference3d extends Operand implements ParsedThing 32 { 33 36 private static Logger logger = Logger.getLogger(CellReference3d.class); 37 38 41 private boolean columnRelative; 42 43 46 private boolean rowRelative; 47 48 51 private int column; 52 53 56 private int row; 57 58 62 private Cell relativeTo; 63 64 67 private int sheet; 68 69 72 private ExternalSheet workbook; 73 74 80 public CellReference3d(Cell rt, ExternalSheet w) 81 { 82 relativeTo = rt; 83 workbook = w; 84 } 85 86 93 public CellReference3d(String s, ExternalSheet w) throws FormulaException 94 { 95 workbook = w; 96 columnRelative = true; 97 rowRelative = true; 98 99 int sep = s.indexOf('!'); 101 String cellString = s.substring(sep+1); 102 column = CellReferenceHelper.getColumn(cellString); 103 row = CellReferenceHelper.getRow(cellString); 104 105 String sheetName = s.substring(0, sep); 107 108 if (sheetName.charAt(0) == '\'' && 110 sheetName.charAt(sheetName.length()-1) == '\'') 111 { 112 sheetName = sheetName.substring(1, sheetName.length() - 1); 113 } 114 sheet = w.getExternalSheetIndex(sheetName); 115 116 if (sheet < 0) 117 { 118 throw new FormulaException(FormulaException.sheetRefNotFound, sheetName); 119 } 120 } 121 122 129 public int read(byte[] data, int pos) 130 { 131 sheet = IntegerHelper.getInt(data[pos], data[pos+1]); 132 row = IntegerHelper.getInt(data[pos+2], data[pos+3]); 133 int columnMask = IntegerHelper.getInt(data[pos+4], data[pos+5]); 134 column = columnMask & 0x00ff; 135 columnRelative = ((columnMask & 0x4000) != 0); 136 rowRelative = ((columnMask & 0x8000) != 0); 137 138 return 6; 139 } 140 141 146 public int getColumn() 147 { 148 return column; 149 } 150 151 156 public int getRow() 157 { 158 return row; 159 } 160 161 166 public void getString(StringBuffer buf) 167 { 168 CellReferenceHelper.getCellReference(sheet, column, !columnRelative, 169 row, !rowRelative, 170 workbook, buf); 171 } 172 173 178 byte[] getBytes() 179 { 180 byte[] data = new byte[7]; 181 data[0] = Token.REF3D.getCode(); 182 183 IntegerHelper.getTwoBytes(sheet, data, 1); 184 IntegerHelper.getTwoBytes(row, data, 3); 185 186 int grcol = column; 187 188 if (rowRelative) 190 { 191 grcol |= 0x8000; 192 } 193 194 if (columnRelative) 195 { 196 grcol |= 0x4000; 197 } 198 199 IntegerHelper.getTwoBytes(grcol, data, 5); 200 201 return data; 202 } 203 204 211 public void adjustRelativeCellReferences(int colAdjust, int rowAdjust) 212 { 213 if (columnRelative) 214 { 215 column += colAdjust; 216 } 217 218 if (rowRelative) 219 { 220 row += rowAdjust; 221 } 222 } 223 224 234 public void columnInserted(int sheetIndex, int col, boolean currentSheet) 235 { 236 if (sheetIndex != sheet) 237 { 238 return; 239 } 240 241 if (column >= col) 242 { 243 column++; 244 } 245 } 246 247 248 258 void columnRemoved(int sheetIndex, int col, boolean currentSheet) 259 { 260 if (sheetIndex != sheet) 261 { 262 return; 263 } 264 265 if (column >= col) 266 { 267 column--; 268 } 269 } 270 271 281 void rowInserted(int sheetIndex, int r, boolean currentSheet) 282 { 283 if (sheetIndex != sheet) 284 { 285 return; 286 } 287 288 if (row >= r) 289 { 290 row++; 291 } 292 } 293 294 304 void rowRemoved(int sheetIndex, int r, boolean currentSheet) 305 { 306 if (sheetIndex != sheet) 307 { 308 return; 309 } 310 311 if (row >= r) 312 { 313 row--; 314 } 315 } 316 } 317 318 319 320 | Popular Tags |