1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 34 35 public class SharedFormulaRecord 36 extends Record 37 { 38 public final static short sid = 0x4BC; 39 private short size = 0; 40 private byte[] thedata = null; 41 int offset = 0; 42 43 public SharedFormulaRecord() 44 { 45 } 46 47 53 54 public SharedFormulaRecord(short id, short size, byte [] data) 55 { 56 super(id, size, data); 57 58 this.fillFields(data, size, 0); 59 } 60 61 64 65 public int serialize(int offset, byte [] data) 66 { 67 if (thedata == null) 68 { 69 thedata = new byte[ 0 ]; 70 } 71 LittleEndian.putShort(data, 0 + offset, sid); 72 LittleEndian.putShort(data, 2 + offset, ( short ) (thedata.length)); 73 if (thedata.length > 0) 74 { 75 System.arraycopy(thedata, 0, data, 4 + offset, thedata.length); 76 } 77 return getRecordSize(); 78 } 79 80 public int getRecordSize() 81 { 82 int retval = 4; 83 84 if (thedata != null) 85 { 86 retval += thedata.length; 87 } 88 return retval; 89 } 90 91 92 protected void validateSid(short id) 93 { 94 if (id != this.sid) 95 { 96 throw new RecordFormatException("Not a valid SharedFormula"); 97 } 98 99 } 100 101 104 105 public String toString() 106 { 107 StringBuffer buffer = new StringBuffer (); 108 109 buffer.append("[SHARED FORMULA RECORD:" + Integer.toHexString(sid) + "]\n"); 110 buffer.append(" .id = ").append(Integer.toHexString(sid)) 111 .append("\n"); 112 buffer.append("[/SHARED FORMULA RECORD]\n"); 113 return buffer.toString(); 114 } 115 116 public short getSid() 117 { 118 return this.sid; 119 } 120 121 124 protected void fillFields(byte [] data, short size, int offset) 125 { 126 thedata = new byte[size]; 127 System.arraycopy(data, 0, thedata, 0, size); 128 129 } 130 131 134 public boolean isInValueSection() 135 { 136 return true; 137 } 138 139 140 143 public boolean isValue() { 144 return true; 145 } 146 147 public Object clone() { 148 SharedFormulaRecord rec = new SharedFormulaRecord(); 149 rec.offset = offset; 150 rec.size = size; 151 rec.thedata = thedata; 152 return rec; 153 } 154 } 155 | Popular Tags |