1 19 20 package jxl.read.biff; 21 22 import java.text.DecimalFormat ; 23 import java.text.NumberFormat ; 24 25 import common.Logger; 26 import common.Assert; 27 28 import jxl.NumberCell; 29 import jxl.CellType; 30 import jxl.NumberFormulaCell; 31 import jxl.biff.IntegerHelper; 32 import jxl.biff.DoubleHelper; 33 import jxl.biff.FormulaData; 34 import jxl.biff.WorkbookMethods; 35 import jxl.biff.FormattingRecords; 36 import jxl.biff.formula.FormulaParser; 37 import jxl.biff.formula.ExternalSheet; 38 import jxl.biff.formula.FormulaException; 39 40 44 public class SharedNumberFormulaRecord extends BaseSharedFormulaRecord 45 implements NumberCell, FormulaData, NumberFormulaCell 46 { 47 50 private static Logger logger = 51 Logger.getLogger(SharedNumberFormulaRecord.class); 52 55 private double value; 56 59 private NumberFormat format; 60 63 private FormattingRecords formattingRecords; 64 65 68 private static DecimalFormat defaultFormat = new DecimalFormat ("#.###"); 69 70 81 public SharedNumberFormulaRecord(Record t, 82 File excelFile, 83 double v, 84 FormattingRecords fr, 85 ExternalSheet es, 86 WorkbookMethods nt, 87 SheetImpl si) 88 { 89 super(t, fr, es, nt, si, excelFile.getPos()); 90 value = v; 91 format = defaultFormat; } 94 95 102 final void setNumberFormat(NumberFormat f) 103 { 104 if (f != null) 105 { 106 format = f; 107 } 108 } 109 110 115 public double getValue() 116 { 117 return value; 118 } 119 120 125 public String getContents() 126 { 127 return format.format(value); 128 } 129 130 135 public CellType getType() 136 { 137 return CellType.NUMBER_FORMULA; 138 } 139 140 147 public byte[] getFormulaData() throws FormulaException 148 { 149 if (!getSheet().getWorkbookBof().isBiff8()) 150 { 151 throw new FormulaException(FormulaException.biff8Supported); 152 } 153 154 FormulaParser fp = new FormulaParser 157 (getTokens(), this, 158 getExternalSheet(), getNameTable(), 159 getSheet().getWorkbook().getSettings()); 160 fp.parse(); 161 byte[] rpnTokens = fp.getBytes(); 162 163 byte[] data = new byte[rpnTokens.length + 22]; 164 165 IntegerHelper.getTwoBytes(getRow(), data, 0); 167 IntegerHelper.getTwoBytes(getColumn(), data, 2); 168 IntegerHelper.getTwoBytes(getXFIndex(), data, 4); 169 DoubleHelper.getIEEEBytes(value, data, 6); 170 171 System.arraycopy(rpnTokens, 0, data, 22, rpnTokens.length); 173 IntegerHelper.getTwoBytes(rpnTokens.length, data, 20); 174 175 byte[] d = new byte[data.length - 6]; 177 System.arraycopy(data, 6, d, 0, data.length - 6); 178 179 return d; 180 } 181 182 188 public NumberFormat getNumberFormat() 189 { 190 return format; 191 } 192 } 193 194 195 196 197 198 199 200 201 202 | Popular Tags |