1 19 20 package jxl.read.biff; 21 22 import common.Assert; 23 import common.Logger; 24 25 import jxl.CellType; 26 import jxl.WorkbookSettings; 27 import jxl.biff.FormattingRecords; 28 import jxl.biff.IntegerHelper; 29 import jxl.biff.DoubleHelper; 30 import jxl.biff.WorkbookMethods; 31 import jxl.biff.formula.ExternalSheet; 32 33 36 class FormulaRecord extends CellValue 37 { 38 41 private static Logger logger = Logger.getLogger(FormulaRecord.class); 42 43 46 private CellValue formula; 47 48 51 private boolean shared; 52 53 57 private static class IgnoreSharedFormula {}; 58 public static final IgnoreSharedFormula ignoreSharedFormula 59 = new IgnoreSharedFormula(); 60 61 74 public FormulaRecord(Record t, 75 File excelFile, 76 FormattingRecords fr, 77 ExternalSheet es, 78 WorkbookMethods nt, 79 SheetImpl si, 80 WorkbookSettings ws) 81 { 82 super(t, fr, si); 83 84 byte[] data = getRecord().getData(); 85 86 shared = false; 87 88 int grbit = IntegerHelper.getInt(data[14], data[15]); 90 if ((grbit & 0x08) != 0) 91 { 92 shared = true; 93 94 if (data[6] == 0 && data[12] == -1 && data[13] == -1) 95 { 96 formula = new SharedStringFormulaRecord 98 (t, excelFile, fr, es, nt, si, ws); 99 } 100 else 101 { 102 double value = DoubleHelper.getIEEEDouble(data, 6); 104 SharedNumberFormulaRecord snfr = new SharedNumberFormulaRecord 105 (t, excelFile, value, fr, es, nt, si); 106 snfr.setNumberFormat(fr.getNumberFormat(getXFIndex())); 107 formula = snfr; 108 } 109 110 return; 111 } 112 113 if (data[6] == 0 && data[12] == -1 && data[13] == -1) 116 { 117 formula = new StringFormulaRecord(t, excelFile, fr, es, nt, si, ws); 119 } 120 else if (data[6] == 1 && 121 data[12] == -1 && 122 data[13] == -1) 123 { 124 formula = new BooleanFormulaRecord(t, fr, es, nt, si); 127 } 128 else if (data[6] == 2 && 129 data[12] == -1 && 130 data[13] == -1) 131 { 132 formula = new ErrorFormulaRecord(t, fr, es, nt, si); 134 } 135 else if (data[6] == 3 && data[12] == -1 && data[13] == -1) 136 { 137 formula = new StringFormulaRecord(t, fr, es, nt, si); 139 } 140 else 141 { 142 formula = new NumberFormulaRecord(t, fr, es, nt, si); 144 } 145 } 146 147 162 public FormulaRecord(Record t, 163 File excelFile, 164 FormattingRecords fr, 165 ExternalSheet es, 166 WorkbookMethods nt, 167 IgnoreSharedFormula i, 168 SheetImpl si, 169 WorkbookSettings ws) 170 { 171 super(t, fr, si); 172 byte[] data = getRecord().getData(); 173 174 shared = false; 175 176 if (data[6] == 0 && data[12] == -1 && data[13] == -1) 179 { 180 formula = new StringFormulaRecord(t, excelFile, fr, es, nt, si, ws); 182 } 183 else if (data[6] == 1 && 184 data[12] == -1 && 185 data[13] == -1) 186 { 187 formula = new BooleanFormulaRecord(t, fr, es, nt, si); 190 } 191 else if (data[6] == 2 && 192 data[12] == -1 && 193 data[13] == -1) 194 { 195 formula = new ErrorFormulaRecord(t, fr, es, nt, si); 197 } 198 else 199 { 200 formula = new NumberFormulaRecord(t, fr, es, nt, si); 202 } 203 } 204 205 210 public String getContents() 211 { 212 Assert.verify(false); 213 return ""; 214 } 215 216 221 public CellType getType() 222 { 223 Assert.verify(false); 224 return CellType.EMPTY; 225 } 226 227 232 final CellValue getFormula() 233 { 234 return formula; 235 } 236 237 243 final boolean isShared() 244 { 245 return shared; 246 } 247 248 } 249 250 251 252 253 254 255 | Popular Tags |