KickJava   Java API By Example, From Geeks To Geeks.

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


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.DecimalFormat JavaDoc;
23 import java.text.NumberFormat JavaDoc;
24
25 import common.Logger;
26
27 import jxl.NumberCell;
28 import jxl.CellType;
29 import jxl.biff.DoubleHelper;
30 import jxl.biff.FormattingRecords;
31
32 /**
33  * A number record. This is stored as 8 bytes, as opposed to the
34  * 4 byte RK record
35  */

36 class NumberRecord extends CellValue implements NumberCell
37 {
38   /**
39    * The logger
40    */

41   private static Logger logger = Logger.getLogger(NumberRecord.class);
42
43   /**
44    * The value
45    */

46   private double value;
47
48   /**
49    * The java equivalent of the excel format
50    */

51   private NumberFormat JavaDoc format;
52
53   /**
54    * The formatter to convert the value into a string
55    */

56   private static DecimalFormat JavaDoc defaultFormat = new DecimalFormat JavaDoc("#.###");
57
58   /**
59    * Constructs this object from the raw data
60    *
61    * @param t the raw data
62    * @param fr the available formats
63    * @param si the sheet
64    */

65   public NumberRecord(Record t, FormattingRecords fr, SheetImpl si)
66   {
67     super(t, fr, si);
68     byte[] data = getRecord().getData();
69
70     value = DoubleHelper.getIEEEDouble(data, 6);
71
72     // Now get the number format
73
format = fr.getNumberFormat(getXFIndex());
74     if (format == null)
75     {
76       format = defaultFormat;
77     }
78   }
79
80   /**
81    * Accessor for the value
82    *
83    * @return the value
84    */

85   public double getValue()
86   {
87     return value;
88   }
89
90   /**
91    * Returns the contents of this cell as a string
92    *
93    * @return the value formatted into a string
94    */

95   public String JavaDoc getContents()
96   {
97     return format.format(value);
98   }
99
100   /**
101    * Accessor for the cell type
102    *
103    * @return the cell type
104    */

105   public CellType getType()
106   {
107     return CellType.NUMBER;
108   }
109
110   /**
111    * Gets the NumberFormat used to format this cell. This is the java
112    * equivalent of the Excel format
113    *
114    * @return the NumberFormat used to format the cell
115    */

116   public NumberFormat JavaDoc getNumberFormat()
117   {
118     return format;
119   }
120 }
121
122
123
124
Popular Tags