1 19 20 package jxl.read.biff; 21 22 import java.text.DecimalFormat ; 23 import java.text.NumberFormat ; 24 25 import common.Logger; 26 27 import jxl.NumberCell; 28 import jxl.CellType; 29 import jxl.NumberFormulaCell; 30 import jxl.biff.FormattingRecords; 31 import jxl.biff.FormulaData; 32 import jxl.biff.WorkbookMethods; 33 import jxl.biff.DoubleHelper; 34 import jxl.biff.formula.FormulaParser; 35 import jxl.biff.formula.ExternalSheet; 36 import jxl.biff.formula.FormulaException; 37 38 41 class NumberFormulaRecord extends CellValue 42 implements NumberCell, FormulaData, NumberFormulaCell 43 { 44 47 private static Logger logger = Logger.getLogger(NumberFormulaRecord.class); 48 49 52 private double value; 53 54 57 private NumberFormat format; 58 59 62 private static final DecimalFormat defaultFormat = 63 new DecimalFormat ("#.###"); 64 65 68 private String formulaString; 69 70 73 private ExternalSheet externalSheet; 74 75 78 private WorkbookMethods nameTable; 79 80 83 private byte[] data; 84 85 94 public NumberFormulaRecord(Record t, FormattingRecords fr, 95 ExternalSheet es, WorkbookMethods nt, 96 SheetImpl si) 97 { 98 super(t, fr, si); 99 100 externalSheet = es; 101 nameTable = nt; 102 data = getRecord().getData(); 103 104 format = fr.getNumberFormat(getXFIndex()); 105 106 if (format == null) 107 { 108 format = defaultFormat; 109 } 110 111 value = DoubleHelper.getIEEEDouble(data, 6); 112 } 113 114 119 public double getValue() 120 { 121 return value; 122 } 123 124 129 public String getContents() 130 { 131 return format.format(value); 132 } 133 134 139 public CellType getType() 140 { 141 return CellType.NUMBER_FORMULA; 142 } 143 144 150 public byte[] getFormulaData() throws FormulaException 151 { 152 if (!getSheet().getWorkbookBof().isBiff8()) 153 { 154 throw new FormulaException(FormulaException.biff8Supported); 155 } 156 157 byte[] d = new byte[data.length - 6]; 159 System.arraycopy(data, 6, d, 0, data.length - 6); 160 161 return d; 162 } 163 164 170 public String getFormula() throws FormulaException 171 { 172 if (formulaString == null) 173 { 174 byte[] tokens = new byte[data.length - 22]; 175 System.arraycopy(data, 22, tokens, 0, tokens.length); 176 FormulaParser fp = new FormulaParser 177 (tokens, this, externalSheet, nameTable, 178 getSheet().getWorkbook().getSettings()); 179 fp.parse(); 180 formulaString = fp.getFormula(); 181 } 182 183 return formulaString; 184 } 185 186 192 public NumberFormat getNumberFormat() 193 { 194 return format; 195 } 196 } 197 | Popular Tags |