KickJava   Java API By Example, From Geeks To Geeks.

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


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 jxl.Range;
23 import jxl.Sheet;
24 import jxl.biff.IntegerHelper;
25 import jxl.biff.RecordData;
26 import jxl.biff.SheetRangeImpl;
27
28 /**
29  * A merged cells record for a given sheet
30  */

31 public class MergedCellsRecord extends RecordData
32 {
33   /**
34    * The ranges of the cells merged on this sheet
35    */

36   private Range[] ranges;
37
38   /**
39    * Constructs this object from the raw data
40    *
41    * @param t the raw data
42    * @param s the sheet
43    */

44   MergedCellsRecord(Record t, Sheet s)
45   {
46     super(t);
47
48     byte[] data = getRecord().getData();
49
50     int numRanges = IntegerHelper.getInt(data[0], data[1]);
51
52     ranges = new Range[numRanges];
53
54     int pos = 2;
55     int firstRow = 0;
56     int lastRow = 0;
57     int firstCol = 0;
58     int lastCol = 0;
59
60     for (int i = 0; i < numRanges; i++)
61     {
62       firstRow = IntegerHelper.getInt(data[pos], data[pos + 1]);
63       lastRow = IntegerHelper.getInt(data[pos + 2], data[pos + 3]);
64       firstCol = IntegerHelper.getInt(data[pos + 4], data[pos + 5]);
65       lastCol = IntegerHelper.getInt(data[pos + 6], data[pos + 7]);
66
67       ranges[i] = new SheetRangeImpl(s, firstCol, firstRow,
68                                      lastCol, lastRow);
69
70       pos += 8;
71     }
72   }
73
74   /**
75    * Gets the ranges which have been merged in this sheet
76    *
77    * @return the ranges of cells which have been merged
78    */

79   public Range[] getRanges()
80   {
81     return ranges;
82   }
83 }
84
85
86
87
88
89
90
91
Popular Tags