1 2 17 18 19 24 package org.apache.poi.hssf.record; 25 26 import org.apache.poi.util.LittleEndian; 27 import org.apache.poi.util.BitField; 28 29 36 37 public class ColumnInfoRecord 38 extends Record 39 { 40 public static final short sid = 0x7d; 41 private short field_1_first_col; 42 private short field_2_last_col; 43 private short field_3_col_width; 44 private short field_4_xf_index; 45 private short field_5_options; 46 static final private BitField hidden = new BitField(0x01); 47 static final private BitField outlevel = new BitField(0x0700); 48 static final private BitField collapsed = new BitField(0x1000); 49 private short field_6_reserved; 50 51 public ColumnInfoRecord() 52 { 53 } 54 55 62 63 public ColumnInfoRecord(short id, short size, byte [] data) 64 { 65 super(id, size, data); 66 } 67 68 76 77 public ColumnInfoRecord(short id, short size, byte [] data, int offset) 78 { 79 super(id, size, data); 80 } 81 82 protected void fillFields(byte [] data, short size, int offset) 83 { 84 field_1_first_col = LittleEndian.getShort(data, 0 + offset); 85 field_2_last_col = LittleEndian.getShort(data, 2 + offset); 86 field_3_col_width = LittleEndian.getShort(data, 4 + offset); 87 field_4_xf_index = LittleEndian.getShort(data, 6 + offset); 88 field_5_options = LittleEndian.getShort(data, 8 + offset); 89 field_6_reserved = data[ 10 + offset ]; 90 } 91 92 protected void validateSid(short id) 93 { 94 if (id != sid) 95 { 96 throw new RecordFormatException("NOT A COLINFO RECORD!!"); 97 } 98 } 99 100 104 105 public void setFirstColumn(short fc) 106 { 107 field_1_first_col = fc; 108 } 109 110 114 115 public void setLastColumn(short lc) 116 { 117 field_2_last_col = lc; 118 } 119 120 124 125 public void setColumnWidth(short cw) 126 { 127 field_3_col_width = cw; 128 } 129 130 135 136 public void setXFIndex(short xfi) 137 { 138 field_4_xf_index = xfi; 139 } 140 141 145 146 public void setOptions(short options) 147 { 148 field_5_options = options; 149 } 150 151 153 158 159 public void setHidden(boolean ishidden) 160 { 161 field_5_options = hidden.setShortBoolean(field_5_options, ishidden); 162 } 163 164 169 170 public void setOutlineLevel(short olevel) 171 { 172 field_5_options = outlevel.setShortValue(field_5_options, olevel); 173 } 174 175 180 181 public void setCollapsed(boolean iscollapsed) 182 { 183 field_5_options = collapsed.setShortBoolean(field_5_options, 184 iscollapsed); 185 } 186 187 189 193 194 public short getFirstColumn() 195 { 196 return field_1_first_col; 197 } 198 199 203 204 public short getLastColumn() 205 { 206 return field_2_last_col; 207 } 208 209 213 214 public short getColumnWidth() 215 { 216 return field_3_col_width; 217 } 218 219 224 225 public short getXFIndex() 226 { 227 return field_4_xf_index; 228 } 229 230 234 235 public short getOptions() 236 { 237 return field_5_options; 238 } 239 240 242 247 248 public boolean getHidden() 249 { 250 return hidden.isSet(field_5_options); 251 } 252 253 258 259 public short getOutlineLevel() 260 { 261 return outlevel.getShortValue(field_5_options); 262 } 263 264 269 270 public boolean getCollapsed() 271 { 272 return collapsed.isSet(field_5_options); 273 } 274 275 public short getSid() 277 { 278 return sid; 279 } 280 281 public int serialize(int offset, byte [] data) 282 { 283 LittleEndian.putShort(data, 0 + offset, sid); 284 LittleEndian.putShort(data, 2 + offset, ( short ) 12); 285 LittleEndian.putShort(data, 4 + offset, getFirstColumn()); 286 LittleEndian.putShort(data, 6 + offset, getLastColumn()); 287 LittleEndian.putShort(data, 8 + offset, getColumnWidth()); 288 LittleEndian.putShort(data, 10 + offset, getXFIndex()); 289 LittleEndian.putShort(data, 12 + offset, getOptions()); 290 LittleEndian.putShort(data, 14 + offset, 291 ( short ) 0x0); return getRecordSize(); 293 } 294 295 public int getRecordSize() 296 { 297 return 16; 298 } 299 300 public String toString() 301 { 302 StringBuffer buffer = new StringBuffer (); 303 304 buffer.append("[COLINFO]\n"); 305 buffer.append("colfirst = ").append(getFirstColumn()) 306 .append("\n"); 307 buffer.append("collast = ").append(getLastColumn()) 308 .append("\n"); 309 buffer.append("colwidth = ").append(getColumnWidth()) 310 .append("\n"); 311 buffer.append("xfindex = ").append(getXFIndex()).append("\n"); 312 buffer.append("options = ").append(getOptions()).append("\n"); 313 buffer.append(" hidden = ").append(getHidden()).append("\n"); 314 buffer.append(" olevel = ").append(getOutlineLevel()) 315 .append("\n"); 316 buffer.append(" collapsed = ").append(getCollapsed()) 317 .append("\n"); 318 buffer.append("[/COLINFO]\n"); 319 return buffer.toString(); 320 } 321 322 public Object clone() { 323 ColumnInfoRecord rec = new ColumnInfoRecord(); 324 rec.field_1_first_col = field_1_first_col; 325 rec.field_2_last_col = field_2_last_col; 326 rec.field_3_col_width = field_3_col_width; 327 rec.field_4_xf_index = field_4_xf_index; 328 rec.field_5_options = field_5_options; 329 rec.field_6_reserved = field_6_reserved; 330 return rec; 331 } 332 } 333 | Popular Tags |