KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > 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.write.biff;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import common.Assert;
26 import jxl.CellType;
27 import jxl.Range;
28 import jxl.Cell;
29 import jxl.write.Blank;
30 import jxl.write.WritableSheet;
31 import jxl.write.WritableCell;
32 import jxl.write.WritableHyperlink;
33 import jxl.write.WriteException;
34 import jxl.biff.IntegerHelper;
35 import jxl.biff.StringHelper;
36 import jxl.biff.CellReferenceHelper;
37 import jxl.biff.WritableRecordData;
38 import jxl.biff.Type;
39 import jxl.biff.SheetRangeImpl;
40
41 /**
42  * A number record. This is stored as 8 bytes, as opposed to the
43  * 4 byte RK record
44  */

45 public class MergedCellsRecord extends WritableRecordData
46 {
47   /**
48    * The ranges of all the cells which are merged on this sheet
49    */

50   private ArrayList JavaDoc ranges;
51
52   /**
53    * Constructs a merged cell record
54    *
55    * @param ws the sheet containing the merged cells
56    */

57   protected MergedCellsRecord(ArrayList JavaDoc mc)
58   {
59     super(Type.MERGEDCELLS);
60
61     ranges = mc;
62   }
63
64   /**
65    * Gets the raw data for output to file
66    *
67    * @return the data to write to file
68    */

69   public byte[] getData()
70   {
71     byte[] data = new byte[ranges.size() * 8 + 2];
72
73     // Set the number of ranges
74
IntegerHelper.getTwoBytes(ranges.size(), data, 0);
75
76     int pos = 2;
77     Range range = null;
78     for (int i = 0; i < ranges.size() ; i++)
79     {
80       range = (Range) ranges.get(i);
81
82       // Set the various cell records
83
Cell tl = range.getTopLeft();
84       Cell br = range.getBottomRight();
85       
86       IntegerHelper.getTwoBytes(tl.getRow(), data, pos);
87       IntegerHelper.getTwoBytes(br.getRow(), data, pos+2);
88       IntegerHelper.getTwoBytes(tl.getColumn(), data, pos+4);
89       IntegerHelper.getTwoBytes(br.getColumn(), data, pos+6);
90
91       pos += 8;
92     }
93
94     return data;
95   }
96
97 }
98
99
100
101
102
103
104
105
Popular Tags