KickJava   Java API By Example, From Geeks To Geeks.

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


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 common.Logger;
23
24 import jxl.biff.IntegerHelper;
25 import jxl.biff.RecordData;
26
27 /**
28  * Contains the cell dimensions of this worksheet
29  */

30 class DimensionRecord extends RecordData
31 {
32   /**
33    * The logger
34    */

35   private static Logger logger = Logger.getLogger(DimensionRecord.class);
36
37   /**
38    * The number of rows in this sheet
39    */

40   private int numRows;
41   /**
42    * The number of columns in this worksheet
43    */

44   private int numCols;
45
46   /**
47    * Dummy indicators for overloading the constructor
48    */

49   private static class Biff7 {};
50   public static Biff7 biff7 = new Biff7();
51
52   /**
53    * Constructs the dimensions from the raw data
54    *
55    * @param t the raw data
56    */

57   public DimensionRecord(Record t)
58   {
59     super(t);
60     byte[] data = t.getData();
61
62     // Sometimes, if the spreadsheet is being generated by dodgy VB modules,
63
// even though the excel format is biff8, the dimension record is
64
// generated in the old biff 7 format. This horrible if construct
65
// handles that eventuality
66
if (data.length == 10)
67     {
68       read10ByteData(data);
69     }
70     else
71     {
72       read14ByteData(data);
73     }
74   }
75
76   /**
77    * Constructs the dimensions from the raw data
78    *
79    * @param t the raw data
80    * @param biff7 an indicator to initialise this record for biff 7 format
81    */

82   public DimensionRecord(Record t, Biff7 biff7)
83   {
84     super(t);
85     byte[] data = t.getData();
86     read10ByteData(data);
87   }
88
89   /**
90    * Reads in the data for data records of length 10
91    * @param data the data to read
92    */

93   private void read10ByteData(byte[] data)
94   {
95     numRows = IntegerHelper.getInt(data[2], data[3]);
96     numCols = IntegerHelper.getInt(data[6], data[7]);
97   }
98
99   /**
100    * Reads in the data for data records of length 14
101    * @param data the data to read
102    */

103   private void read14ByteData(byte[] data)
104   {
105     numRows = IntegerHelper.getInt(data[4], data[5], data[6], data[7]);
106     numCols = IntegerHelper.getInt(data[10], data[11]);
107   }
108
109   /**
110    * Accessor for the number of rows in this sheet
111    *
112    * @return the number of rows
113    */

114   public int getNumberOfRows()
115   {
116     return numRows;
117   }
118
119   /**
120    * Accessor for the number of columns in this sheet
121    *
122    * @return the number of columns
123    */

124   public int getNumberOfColumns()
125   {
126     return numCols;
127   }
128 }
129
130
131
132
133
134
135
136
Popular Tags