KickJava   Java API By Example, From Geeks To Geeks.

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


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.IntegerHelper;
30 import jxl.biff.FormattingRecords;
31
32 /**
33  * An individual RK record
34  */

35 class RKRecord extends CellValue implements NumberCell
36 {
37   /**
38    * The logger
39    */

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

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

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

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

64   public RKRecord(Record t, FormattingRecords fr, SheetImpl si)
65   {
66     super(t, fr, si);
67     byte[] data = getRecord().getData();
68     int rknum = IntegerHelper.getInt(data[6], data[7], data[8], data[9]);
69     value = RKHelper.getDouble(rknum);
70
71     // Now get the number format
72
format = fr.getNumberFormat(getXFIndex());
73     if (format == null)
74     {
75       format = defaultFormat;
76     }
77   }
78
79   /**
80    * Accessor for the value
81    *
82    * @return the value
83    */

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

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

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

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