KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > WritableWorkbook


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;
21
22 import java.io.IOException JavaDoc;
23
24 import jxl.Workbook;
25 import jxl.Range;
26 import jxl.format.UnderlineStyle;
27 import jxl.format.Colour;
28
29 /**
30  * A writable workbook
31  */

32 public abstract class WritableWorkbook
33 {
34   // Globally available stuff
35

36   /**
37    * The default font for Cell formats
38    */

39   public static final WritableFont ARIAL_10_PT =
40     new WritableFont(WritableFont.ARIAL);
41
42   /**
43    * The font used for hyperlinks
44    */

45   public static final WritableFont HYPERLINK_FONT =
46     new WritableFont(WritableFont.ARIAL,
47                      WritableFont.DEFAULT_POINT_SIZE,
48                      WritableFont.NO_BOLD,
49                      false,
50                      UnderlineStyle.SINGLE,
51                      Colour.BLUE);
52
53   /**
54    * The default style for cells
55    */

56   public static final WritableCellFormat NORMAL_STYLE =
57     new WritableCellFormat(ARIAL_10_PT, NumberFormats.DEFAULT);
58
59   /**
60    * The style used for hyperlinks
61    */

62   public static final WritableCellFormat HYPERLINK_STYLE =
63     new WritableCellFormat(HYPERLINK_FONT);
64
65   /**
66    * A cell format used to hide the cell contents
67    */

68   public static final WritableCellFormat HIDDEN_STYLE =
69     new WritableCellFormat(new DateFormat(";;;"));
70
71   /**
72    * Constructor used by the implemenation class
73    */

74   protected WritableWorkbook()
75   {
76   }
77
78   /**
79    * Gets the sheets within this workbook. Use of this method for
80    * large worksheets can cause performance problems.
81    *
82    * @return an array of the individual sheets
83    */

84   public abstract WritableSheet[] getSheets();
85
86   /**
87    * Gets the sheet names
88    *
89    * @return an array of strings containing the sheet names
90    */

91   public abstract String JavaDoc[] getSheetNames();
92
93   /**
94    * Gets the specified sheet within this workbook
95    *
96    * @param index the zero based index of the reQuired sheet
97    * @return The sheet specified by the index
98    * @exception IndexOutOfBoundException when index refers to a non-existent
99    * sheet
100    */

101   public abstract WritableSheet getSheet(int index)
102     throws IndexOutOfBoundsException JavaDoc;
103
104   /**
105    * Gets the sheet with the specified name from within this workbook
106    *
107    * @param name the sheet name
108    * @return The sheet with the specified name, or null if it is not found
109    */

110   public abstract WritableSheet getSheet(String JavaDoc name);
111
112   /**
113    * Returns the number of sheets in this workbook
114    *
115    * @return the number of sheets in this workbook
116    */

117   public abstract int getNumberOfSheets();
118
119   /**
120    * Closes this workbook, and makes any memory allocated available
121    * for garbage collection. Also closes the underlying output stream
122    * if necessary.
123    *
124    * @exception java.io.IOException
125    * @exception WriteException
126    */

127   public abstract void close() throws IOException JavaDoc, WriteException;
128
129   /**
130    * Creates, and returns a worksheet at the specified position
131    * with the specified name
132    * If the index specified is less than or equal to zero, the new sheet
133    * is created at the beginning of the workbook. If the index is greater
134    * than the number of sheet, then the sheet is created at the
135    * end of the workbook.
136    *
137    * @param name the sheet name
138    * @param index the index number at which to insert
139    * @return the new sheet
140    */

141   public abstract WritableSheet createSheet(String JavaDoc name, int index);
142
143   /**
144    * Copies the specified sheet and places it at the index
145    * specified by the parameter
146    *
147    * @param s the index of the sheet to copy
148    * @param name the name of the new sheet
149    * @param index the position of the new sheet
150    */

151   public abstract void copySheet(int s, String JavaDoc name, int index);
152
153   /**
154    * Copies the specified sheet and places it at the index
155    * specified by the parameter
156    *
157    * @param s the name of the sheet to copy
158    * @param name the name of the new sheet
159    * @param index the position of the new sheet
160    */

161   public abstract void copySheet(String JavaDoc s, String JavaDoc name, int index);
162
163   /**
164    * Removes the sheet at the specified index from this workbook
165    *
166    * @param index the sheet index to remove
167    */

168   public abstract void removeSheet(int index);
169
170   /**
171    * Moves the specified sheet within this workbook to another index
172    * position.
173    *
174    * @param fromIndex the zero based index of the required sheet
175    * @param toIndex the zero based index of the required sheet
176    * @return the sheet that has been moved
177    */

178   public abstract WritableSheet moveSheet(int fromIndex, int toIndex);
179
180   /**
181    * Writes out the data held in this workbook in Excel format
182    * @exception IOException
183    */

184   public abstract void write() throws IOException JavaDoc;
185
186   /**
187    * Indicates whether or not this workbook is protected
188    *
189    * @param prot Protected flag
190    */

191   public abstract void setProtected(boolean prot);
192
193   /**
194    * Sets the RGB value for the specified colour for this workbook
195    *
196    * @param c the colour whose RGB value is to be overwritten
197    * @param r the red portion to set (0-255)
198    * @param g the green portion to set (0-255)
199    * @param b the blue portion to set (0-255)
200    */

201   public abstract void setColourRGB(Colour c, int r, int g, int b);
202
203   /**
204    * This method can be used to create a writable clone of some other
205    * workbook
206    *
207    * @param w the workdoock to copy
208    * @deprecated Copying now occurs implicitly as part of the overloaded
209    * factory method Workbook.createWorkbood
210    */

211   public void copy(Workbook w)
212   {
213     // Was an abstract method - leave the method body blank
214
}
215
216   /**
217    * Gets the named cell from this workbook. The name refers to a
218    * range of cells, then the cell on the top left is returned. If
219    * the name cannot be, null is returned
220    *
221    * @param the name of the cell/range to search for
222    * @return the cell in the top left of the range if found, NULL
223    * otherwise
224    */

225   public abstract WritableCell findCellByName(String JavaDoc name);
226
227   /**
228    * Gets the named range from this workbook. The Range object returns
229    * contains all the cells from the top left to the bottom right
230    * of the range.
231    * If the named range comprises an adjacent range,
232    * the Range[] will contain one object; for non-adjacent
233    * ranges, it is necessary to return an array of length greater than
234    * one.
235    * If the named range contains a single cell, the top left and
236    * bottom right cell will be the same cell
237    *
238    * @param the name of the cell/range to search for
239    * @return the range of cells
240    */

241   public abstract Range[] findByName(String JavaDoc name);
242
243   /**
244    * Gets the named ranges
245    *
246    * @return the list of named cells within the workbook
247    */

248   public abstract String JavaDoc[] getRangeNames();
249
250   /**
251    * Add new named area to this workbook with the given information.
252    *
253    * @param name name to be created.
254    * @param sheet sheet containing the name
255    * @param firstCol first column this name refers to.
256    * @param firstRow first row this name refers to.
257    * @param lastCol last column this name refers to.
258    * @param lastRow last row this name refers to.
259    */

260   public abstract void addNameArea(String JavaDoc name,
261                                    WritableSheet sheet,
262                                    int firstCol,
263                                    int firstRow,
264                                    int lastCol,
265                                    int lastRow);
266
267
268   /**
269    * Sets a new output file. This allows the smae workbook to be
270    * written to various different output files without having to
271    * read in any templates again
272    *
273    * @param fileName the file name
274    * @exception IOException
275    */

276   public abstract void setOutputFile(java.io.File JavaDoc fileName) throws IOException JavaDoc;
277
278 }
279
Popular Tags