1 19 20 package jxl.write.biff; 21 22 import jxl.biff.Type; 23 import jxl.biff.IntegerHelper; 24 import jxl.biff.StringHelper; 25 import jxl.biff.DoubleHelper; 26 import jxl.biff.WritableRecordData; 27 28 32 class NameRecord extends WritableRecordData 33 { 34 37 private byte[] data; 38 39 42 private String name; 43 44 47 private int index; 48 49 53 private int sheetRef = 0; 54 55 58 class NameRange 59 { 60 private int columnFirst; 61 private int rowFirst; 62 private int columnLast; 63 private int rowLast; 64 private int externalSheet; 65 66 NameRange(jxl.read.biff.NameRecord.NameRange nr) 67 { 68 columnFirst = nr.getFirstColumn(); 69 rowFirst = nr.getFirstRow(); 70 columnLast = nr.getLastColumn(); 71 rowLast = nr.getLastRow(); 72 externalSheet = nr.getExternalSheet(); 73 } 74 75 78 NameRange(int theSheet, 79 int theStartRow, 80 int theEndRow, 81 int theStartCol, 82 int theEndCol) 83 { 84 columnFirst = theStartCol; 85 rowFirst = theStartRow; 86 columnLast = theEndCol; 87 rowLast = theEndRow; 88 externalSheet = theSheet; 89 } 90 91 int getFirstColumn() {return columnFirst;} 92 int getFirstRow() {return rowFirst;} 93 int getLastColumn() {return columnLast;} 94 int getLastRow() {return rowLast;} 95 int getExternalSheet() { return externalSheet;} 96 97 byte[] getData() 98 { 99 byte[] d = new byte[10]; 100 101 IntegerHelper.getTwoBytes(sheetRef, d, 0); 103 104 IntegerHelper.getTwoBytes(rowFirst, d, 2); 106 107 IntegerHelper.getTwoBytes(rowLast, d, 4); 109 110 IntegerHelper.getTwoBytes(columnFirst & 0xff, d, 6); 112 113 IntegerHelper.getTwoBytes(columnLast & 0xff, d, 8); 115 116 return d; 117 } 118 119 } 120 121 124 private NameRange[] ranges; 125 126 private static final int cellReference = 0x3a; 128 private static final int areaReference = 0x3b; 129 private static final int subExpression = 0x29; 130 private static final int union = 0x10; 131 132 137 public NameRecord(jxl.read.biff.NameRecord sr, int ind) 138 { 139 super(Type.NAME); 140 141 data = sr.getData(); 142 name = sr.getName(); 143 sheetRef = sr.getSheetRef(); 144 index = ind; 145 146 jxl.read.biff.NameRecord.NameRange[] r = sr.getRanges(); 148 ranges = new NameRange[r.length]; 149 for (int i = 0 ; i < ranges.length ; i++) 150 { 151 ranges[i] = new NameRange(r[i]); 152 } 153 } 154 155 166 NameRecord(String theName, 167 int theIndex, 168 int theSheet, 169 int theStartRow, 170 int theEndRow, 171 int theStartCol, 172 int theEndCol) 173 { 174 super(Type.NAME); 175 176 name = theName; 177 index = theIndex; sheetRef = 0; 180 ranges = new NameRange[1]; 181 ranges[0] = new NameRange(theSheet, 182 theStartRow, 183 theEndRow, 184 theStartCol, 185 theEndCol); 186 } 187 188 193 public byte[] getData() 194 { 195 if (data != null) 196 { 197 return data; 199 } 200 201 final int NAME_HEADER_LENGTH = 15; 202 final byte AREA_RANGE_LENGTH = 11; 203 final byte AREA_REFERENCE = 0x3b; 204 205 data = new byte[NAME_HEADER_LENGTH + 206 name.length() + 207 AREA_RANGE_LENGTH]; 208 209 int options = 0; 211 IntegerHelper.getTwoBytes(options, data, 0); 212 213 data[2] = 0; 215 216 data[3] = (byte) name.length(); 218 219 IntegerHelper.getTwoBytes(AREA_RANGE_LENGTH, data, 4); 221 222 IntegerHelper.getTwoBytes(ranges[0].externalSheet, data, 6); 224 IntegerHelper.getTwoBytes(ranges[0].externalSheet, data, 8); 225 226 229 StringHelper.getBytes(name, data, 15); 231 232 233 int pos = name.length() + 15; 235 236 data[pos] = areaReference; 238 239 byte[] rd = ranges[0].getData(); 241 System.arraycopy(rd, 0, data, pos+1, rd.length); 242 243 return data; 244 } 245 246 251 public String getName() 252 { 253 return name; 254 } 255 256 261 public int getIndex() 262 { 263 return index; 264 } 265 266 272 public int getSheetRef() 273 { 274 return sheetRef; 275 } 276 277 282 public void setSheetRef(int i) 283 { 284 sheetRef = i; 285 IntegerHelper.getTwoBytes(sheetRef, data, 8); 286 } 287 288 292 public NameRange[] getRanges() 293 { 294 return ranges; 295 } 296 } 297 298 | Popular Tags |