KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > read > biff > DateFormulaRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.read.biff;
21
22 import java.text.NumberFormat JavaDoc;
23
24 import jxl.DateCell;
25 import jxl.CellType;
26 import jxl.DateFormulaCell;
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 /**
35  * A date formula's last calculated value
36  */

37 class DateFormulaRecord extends DateRecord
38   implements DateCell, FormulaData, DateFormulaCell
39 {
40   /**
41    * The formula as an excel string
42    */

43   private String JavaDoc formulaString;
44
45   /**
46    * A handle to the class needed to access external sheets
47    */

48   private ExternalSheet externalSheet;
49
50   /**
51    * A handle to the name table
52    */

53   private WorkbookMethods nameTable;
54
55   /**
56    * The raw data
57    */

58   private byte[] data;
59
60   /**
61    * Constructs this object from the raw data
62    *
63    * @param t the basic number formula record
64    * @param fr the formatting records
65    * @param es the external sheet
66    * @param nt the name table
67    * @param nf flag indicating whether the 1904 date system is in use
68    * @param si the sheet
69    */

70   public DateFormulaRecord(NumberFormulaRecord t, FormattingRecords fr,
71                            ExternalSheet es, WorkbookMethods nt,
72                            boolean nf, SheetImpl si) throws FormulaException
73   {
74     super(t, t.getXFIndex(), fr, nf, si);
75
76     externalSheet = es;
77     nameTable = nt;
78     data = t.getFormulaData();
79   }
80
81   /**
82    * Returns the cell type
83    *
84    * @return The cell type
85    */

86   public CellType getType()
87   {
88     return CellType.DATE_FORMULA;
89   }
90
91   /**
92    * Gets the raw bytes for the formula. This will include the
93    * parsed tokens array. Used when copying spreadsheets
94    *
95    * @return the raw record data
96    */

97   public byte[] getFormulaData() throws FormulaException
98   {
99     if (!getSheet().getWorkbookBof().isBiff8())
100     {
101       throw new FormulaException(FormulaException.biff8Supported);
102     }
103
104     // Data is already the formula data, so don't do any more manipulation
105
return data;
106   }
107
108   /**
109    * Gets the formula as an excel string
110    *
111    * @return the formula as an excel string
112    * @exception FormulaException
113    */

114   public String JavaDoc getFormula() throws FormulaException
115   {
116     // Note that the standard information was lopped off by the NumberFormula
117
// record when creating this formula
118
if (formulaString == null)
119     {
120       byte[] tokens = new byte[data.length - 16];
121       System.arraycopy(data, 16, tokens, 0, tokens.length);
122       FormulaParser fp = new FormulaParser
123         (tokens, this, externalSheet, nameTable,
124          getSheet().getWorkbook().getSettings());
125       fp.parse();
126       formulaString = fp.getFormula();
127     }
128
129     return formulaString;
130   }
131
132   /**
133    * Interface method which returns the value
134    *
135    * @return the last calculated value of the formula
136    */

137   public double getValue()
138   {
139     return 0;
140   }
141
142   /**
143    * Dummy implementation in order to adhere to the NumberCell interface
144    *
145    * @return NULL
146    */

147   public NumberFormat JavaDoc getNumberFormat()
148   {
149     return null;
150   }
151 }
152
Popular Tags