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 SharedFormulaArea extends Operand implements ParsedThing 30 { 31 private int columnFirst; 32 private int rowFirst; 33 private int columnLast; 34 private int rowLast; 35 36 private boolean columnFirstRelative; 37 private boolean rowFirstRelative; 38 private boolean columnLastRelative; 39 private boolean rowLastRelative; 40 41 45 private Cell relativeTo; 46 47 52 public SharedFormulaArea(Cell rt) 53 { 54 relativeTo = rt; 55 } 56 57 int getFirstColumn() 58 { 59 return columnFirst; 60 } 61 62 int getFirstRow() 63 { 64 return rowFirst; 65 } 66 67 int getLastColumn() 68 { 69 return columnLast; 70 } 71 72 int getLastRow() 73 { 74 return rowLast; 75 } 76 77 84 public int read(byte[] data, int pos) 85 { 86 89 rowFirst = IntegerHelper.getShort(data[pos], data[pos+1]); 90 rowLast = IntegerHelper.getShort(data[pos+2], data[pos+3]); 91 92 int columnMask = IntegerHelper.getInt(data[pos+4], data[pos+5]); 93 columnFirst = columnMask & 0x00ff; 94 columnFirstRelative = ((columnMask & 0x4000) != 0); 95 rowFirstRelative = ((columnMask & 0x8000) != 0); 96 97 if (columnFirstRelative) 98 { 99 columnFirst = relativeTo.getColumn() + columnFirst; 100 } 101 102 if (rowFirstRelative) 103 { 104 rowFirst = relativeTo.getRow() + rowFirst; 105 } 106 107 columnMask = IntegerHelper.getInt(data[pos+6], data[pos+7]); 108 columnLast = columnMask & 0x00ff; 109 110 columnLastRelative = ((columnMask & 0x4000) != 0); 111 rowLastRelative = ((columnMask & 0x8000) != 0); 112 113 if (columnLastRelative) 114 { 115 columnLast = relativeTo.getColumn() + columnLast; 116 } 117 118 if (rowLastRelative) 119 { 120 rowLast = relativeTo.getRow() + rowLast; 121 } 122 123 124 return 8; 125 } 126 127 public void getString(StringBuffer buf) 128 { 129 CellReferenceHelper.getCellReference(columnFirst, rowFirst, buf); 130 buf.append(':'); 131 CellReferenceHelper.getCellReference(columnLast, rowLast, buf); 132 } 133 134 139 byte[] getBytes() 140 { 141 byte[] data = new byte[9]; 142 data[0] = Token.AREA.getCode(); 143 144 IntegerHelper.getTwoBytes(rowFirst, data, 1); 147 IntegerHelper.getTwoBytes(rowLast, data, 3); 148 IntegerHelper.getTwoBytes(columnFirst, data, 5); 149 IntegerHelper.getTwoBytes(columnLast, data, 7); 150 151 return data; 152 } 153 } 154 155 156 157 | Popular Tags |