1 19 20 package jxl.read.biff; 21 22 import common.Assert; 23 24 import jxl.ErrorCell; 25 import jxl.CellType; 26 import jxl.ErrorFormulaCell; 27 import jxl.biff.FormattingRecords; 28 import jxl.biff.FormulaData; 29 import jxl.biff.WorkbookMethods; 30 import jxl.biff.formula.FormulaParser; 31 import jxl.biff.formula.ExternalSheet; 32 import jxl.biff.formula.FormulaException; 33 34 37 class ErrorFormulaRecord extends CellValue 38 implements ErrorCell, FormulaData, ErrorFormulaCell 39 { 40 43 private int errorCode; 44 45 48 private ExternalSheet externalSheet; 49 50 53 private WorkbookMethods nameTable; 54 55 58 private String formulaString; 59 60 63 private byte[] data; 64 65 74 public ErrorFormulaRecord(Record t, FormattingRecords fr, ExternalSheet es, 75 WorkbookMethods nt, 76 SheetImpl si) 77 { 78 super(t, fr, si); 79 80 externalSheet = es; 81 nameTable = nt; 82 data = getRecord().getData(); 83 84 Assert.verify(data[6] == 2); 85 86 errorCode = data[8]; 87 } 88 89 96 public int getErrorCode() 97 { 98 return errorCode; 99 } 100 101 106 public String getContents() 107 { 108 return "ERROR " + errorCode; 109 } 110 111 116 public CellType getType() 117 { 118 return CellType.FORMULA_ERROR; 119 } 120 121 127 public byte[] getFormulaData() throws FormulaException 128 { 129 if (!getSheet().getWorkbookBof().isBiff8()) 130 { 131 throw new FormulaException(FormulaException.biff8Supported); 132 } 133 134 byte[] d = new byte[data.length - 6]; 136 System.arraycopy(data, 6, d, 0, data.length - 6); 137 138 return d; 139 } 140 141 147 public String getFormula() throws FormulaException 148 { 149 if (formulaString == null) 150 { 151 byte[] tokens = new byte[data.length - 22]; 152 System.arraycopy(data, 22, tokens, 0, tokens.length); 153 FormulaParser fp = new FormulaParser 154 (tokens, this, externalSheet, nameTable, 155 getSheet().getWorkbook().getSettings()); 156 fp.parse(); 157 formulaString = fp.getFormula(); 158 } 159 160 return formulaString; 161 } 162 } 163 164 | Popular Tags |