KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > demo > Write


1 /*********************************************************************
2 *
3 * Copyright (C) 2001 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.demo;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Calendar JavaDoc;
26 import java.util.TimeZone JavaDoc;
27 import java.util.Locale JavaDoc;
28 import java.text.SimpleDateFormat JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31
32 import jxl.Workbook;
33 import jxl.WorkbookSettings;
34 import jxl.Range;
35 import jxl.CellView;
36 import jxl.CellReferenceHelper;
37 import jxl.HeaderFooter;
38 import jxl.write.WritableWorkbook;
39 import jxl.write.WritableSheet;
40 import jxl.write.WritableFont;
41 import jxl.write.WritableCellFormat;
42 import jxl.write.NumberFormats;
43 import jxl.write.DateFormats;
44 import jxl.write.Label;
45 import jxl.write.Number;
46 import jxl.write.DateTime;
47 import jxl.write.NumberFormat;
48 import jxl.write.DateFormat;
49 import jxl.write.WriteException;
50 import jxl.write.WritableHyperlink;
51 import jxl.write.Boolean;
52 import jxl.write.Formula;
53 import jxl.write.WritableImage;
54 import jxl.write.WritableCellFeatures;
55 import jxl.format.Alignment;
56 import jxl.format.Border;
57 import jxl.format.BorderLineStyle;
58 import jxl.format.Colour;
59 import jxl.format.UnderlineStyle;
60 import jxl.format.ScriptStyle;
61 import jxl.format.Orientation;
62 import jxl.format.PageOrientation;
63 import jxl.format.PaperSize;
64
65 /**
66  * Demo class which writes a spreadsheet. This demo illustrates most of the
67  * features of the JExcelAPI, such as text, numbers, fonts, number formats and
68  * date formats
69  */

70 public class Write
71 {
72   /**
73    * The filename
74    */

75   private String JavaDoc filename;
76
77   /**
78    * The workbook
79    */

80   private WritableWorkbook workbook;
81
82   /**
83    * Constructor
84    *
85    * @param fn
86    */

87   public Write(String JavaDoc fn)
88   {
89     filename = fn;
90   }
91
92   /**
93    * Uses the JExcelAPI to create a spreadsheet
94    *
95    * @exception IOException
96    * @exception WriteException
97    */

98   public void write() throws IOException JavaDoc, WriteException
99   {
100     WorkbookSettings ws = new WorkbookSettings();
101     ws.setLocale(new Locale JavaDoc("en", "EN"));
102     workbook = Workbook.createWorkbook(new File JavaDoc(filename), ws);
103
104
105     WritableSheet s2 = workbook.createSheet("Number Formats", 0);
106     WritableSheet s3 = workbook.createSheet("Date Formats", 1);
107     WritableSheet s1 = workbook.createSheet("Label Formats", 2);
108     WritableSheet s4 = workbook.createSheet("Borders", 3);
109     WritableSheet s5 = workbook.createSheet("Labels", 4);
110     WritableSheet s6 = workbook.createSheet("Formulas", 5);
111     WritableSheet s7 = workbook.createSheet("Images", 6);
112     //WritableSheet s8 = workbook.createSheet
113
// ("'Illegal chars in name !*%^?': which exceeds max name length",7);
114

115     writeLabelFormatSheet(s1);
116     writeNumberFormatSheet(s2);
117     writeDateFormatSheet(s3);
118     writeBordersSheet(s4);
119     writeLabelsSheet(s5);
120     writeFormulaSheet(s6);
121     writeImageSheet(s7);
122
123     // Modify the colour palette to bright red for the lime colour
124
workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
125
126     // Add a named range to the workbook
127
workbook.addNameArea("namedrange", s4, 1, 11, 5, 14);
128
129     workbook.write();
130     workbook.close();
131   }
132   
133   /**
134    * Writes out a sheet containing the various numerical formats
135    *
136    * @param s
137    */

138   private void writeNumberFormatSheet(WritableSheet s) throws WriteException
139   {
140     WritableCellFormat wrappedText = new WritableCellFormat
141       (WritableWorkbook.ARIAL_10_PT);
142     wrappedText.setWrap(true);
143
144     s.setColumnView(0,20);
145     s.setColumnView(4,20);
146     s.setColumnView(5,20);
147     s.setColumnView(6,20);
148
149     // Floats
150
Label l = new Label(0,0,"+/- Pi - default format", wrappedText);
151     s.addCell(l);
152
153     Number JavaDoc n = new Number JavaDoc(1,0,3.1415926535);
154     s.addCell(n);
155
156     n = new Number JavaDoc(2,0,-3.1415926535);
157     s.addCell(n);
158
159     l = new Label(0,1,"+/- Pi - integer format", wrappedText);
160     s.addCell(l);
161
162     WritableCellFormat cf1 = new WritableCellFormat(NumberFormats.INTEGER);
163     n = new Number JavaDoc(1,1,3.1415926535,cf1);
164     s.addCell(n);
165
166     n = new Number JavaDoc(2,1,-3.1415926535, cf1);
167     s.addCell(n);
168
169     l = new Label(0,2,"+/- Pi - float 2dps", wrappedText);
170     s.addCell(l);
171
172     WritableCellFormat cf2 = new WritableCellFormat(NumberFormats.FLOAT);
173     n = new Number JavaDoc(1,2,3.1415926535,cf2);
174     s.addCell(n);
175
176     n = new Number JavaDoc(2,2,-3.1415926535, cf2);
177     s.addCell(n);
178
179     l = new Label(0,3,"+/- Pi - custom 3dps",
180                   wrappedText);
181     s.addCell(l);
182
183     NumberFormat dp3 = new NumberFormat("#.###");
184     WritableCellFormat dp3cell = new WritableCellFormat(dp3);
185     n = new Number JavaDoc(1,3,3.1415926535,dp3cell);
186     s.addCell(n);
187
188     n = new Number JavaDoc(2,3,-3.1415926535, dp3cell);
189     s.addCell(n);
190
191     l = new Label(0,4,"+/- Pi - custom &3.14",
192                   wrappedText);
193     s.addCell(l);
194
195     NumberFormat pounddp2 = new NumberFormat("&#.00");
196     WritableCellFormat pounddp2cell = new WritableCellFormat(pounddp2);
197     n = new Number JavaDoc(1,4,3.1415926535,pounddp2cell);
198     s.addCell(n);
199
200     n = new Number JavaDoc(2,4,-3.1415926535, pounddp2cell);
201     s.addCell(n);
202
203     l = new Label(0,5,"+/- Pi - custom Text #.### Text",
204                   wrappedText);
205     s.addCell(l);
206
207     NumberFormat textdp4 = new NumberFormat("Text#.####Text");
208     WritableCellFormat textdp4cell = new WritableCellFormat(textdp4);
209     n = new Number JavaDoc(1,5,3.1415926535, textdp4cell);
210     s.addCell(n);
211
212     n = new Number JavaDoc(2,5,-3.1415926535, textdp4cell);
213     s.addCell(n);
214
215     // Integers
216
l = new Label(4,0,"+/- Bilko default format");
217     s.addCell(l);
218     n = new Number JavaDoc(5, 0, 15042699);
219     s.addCell(n);
220     n = new Number JavaDoc(6, 0, -15042699);
221     s.addCell(n);
222
223     l = new Label(4,1,"+/- Bilko float format");
224     s.addCell(l);
225     WritableCellFormat cfi1 = new WritableCellFormat(NumberFormats.FLOAT);
226     n = new Number JavaDoc(5, 1, 15042699, cfi1);
227     s.addCell(n);
228     n = new Number JavaDoc(6, 1, -15042699, cfi1);
229     s.addCell(n);
230
231     l = new Label(4,2,"+/- Thousands separator");
232     s.addCell(l);
233     WritableCellFormat cfi2 = new WritableCellFormat
234       (NumberFormats.THOUSANDS_INTEGER);
235     n = new Number JavaDoc(5, 2, 15042699,cfi2 );
236     s.addCell(n);
237     n = new Number JavaDoc(6, 2, -15042699, cfi2);
238     s.addCell(n);
239
240     l = new Label(4,3,"+/- Accounting red - added 0.01");
241     s.addCell(l);
242     WritableCellFormat cfi3 = new WritableCellFormat
243       (NumberFormats.ACCOUNTING_RED_FLOAT);
244     n = new Number JavaDoc(5, 3, 15042699.01, cfi3);
245     s.addCell(n);
246     n = new Number JavaDoc(6, 3, -15042699.01, cfi3);
247     s.addCell(n);
248
249     l = new Label(4,4,"+/- Percent");
250     s.addCell(l);
251     WritableCellFormat cfi4 = new WritableCellFormat
252       (NumberFormats.PERCENT_INTEGER);
253     n = new Number JavaDoc(5, 4, 15042699, cfi4);
254     s.addCell(n);
255     n = new Number JavaDoc(6, 4, -15042699, cfi4);
256     s.addCell(n);
257
258     l = new Label(4,5,"+/- Exponential - 2dps");
259     s.addCell(l);
260     WritableCellFormat cfi5 = new WritableCellFormat
261       (NumberFormats.EXPONENTIAL);
262     n = new Number JavaDoc(5, 5, 15042699, cfi5);
263     s.addCell(n);
264     n = new Number JavaDoc(6, 5, -15042699, cfi5);
265     s.addCell(n);
266
267     l = new Label(4,6,"+/- Custom exponentional - 3dps", wrappedText);
268     s.addCell(l);
269     NumberFormat edp3 = new NumberFormat("0.000E0");
270     WritableCellFormat edp3Cell = new WritableCellFormat(edp3);
271     n = new Number JavaDoc(5,6,15042699,edp3Cell);
272     s.addCell(n);
273     n = new Number JavaDoc(6,6,-15042699,edp3Cell);
274     s.addCell(n);
275
276     l = new Label(4, 7, "Custom neg brackets", wrappedText);
277     s.addCell(l);
278     NumberFormat negbracks = new NumberFormat("#,##0;(#,##0)");
279     WritableCellFormat negbrackscell = new WritableCellFormat(negbracks);
280     n = new Number JavaDoc(5,7, 15042699, negbrackscell);
281     s.addCell(n);
282     n = new Number JavaDoc(6,7, -15042699, negbrackscell);
283     s.addCell(n);
284
285     l = new Label(4, 8, "Custom neg brackets 2", wrappedText);
286     s.addCell(l);
287     NumberFormat negbracks2 = new NumberFormat("#,##0;(#,##0)a");
288     WritableCellFormat negbrackscell2 = new WritableCellFormat(negbracks2);
289     n = new Number JavaDoc(5,8, 15042699, negbrackscell2);
290     s.addCell(n);
291     n = new Number JavaDoc(6,8, -15042699, negbrackscell2);
292     s.addCell(n);
293
294     l = new Label(4, 9, "Custom percent", wrappedText);
295     s.addCell(l);
296     NumberFormat cuspercent = new NumberFormat("0.0%");
297     WritableCellFormat cuspercentf = new WritableCellFormat(cuspercent);
298     n = new Number JavaDoc(5, 9, 3.14159265, cuspercentf);
299     s.addCell(n);
300     
301
302     // Booleans
303
l = new Label(0,10, "Boolean - TRUE");
304     s.addCell(l);
305     Boolean JavaDoc b = new Boolean JavaDoc(1,10, true);
306     s.addCell(b);
307
308     l = new Label(0,11, "Boolean - FALSE");
309     s.addCell(l);
310     b = new Boolean JavaDoc(1,11,false);
311     s.addCell(b);
312
313     l = new Label(0, 12, "A hidden cell->");
314     s.addCell(l);
315     n = new Number JavaDoc(1, 12, 17, WritableWorkbook.HIDDEN_STYLE);
316     s.addCell(n);
317
318
319     // Lots of numbers
320
for (int row = 0; row < 100; row++)
321     {
322       for (int col = 8; col < 108; col++)
323       {
324         n = new Number JavaDoc(col, row, col+row);
325         s.addCell(n);
326       }
327     }
328
329     // Lots of numbers
330
for (int row = 101; row < 3000; row++)
331     {
332       for (int col = 0; col < 25; col++)
333       {
334         n = new Number JavaDoc(col, row, col+row);
335         s.addCell(n);
336       }
337     }
338   }
339
340   /**
341    * Adds cells to the specified sheet which test the various date formats
342    *
343    * @param s
344    */

345   private void writeDateFormatSheet(WritableSheet s) throws WriteException
346   {
347     WritableCellFormat wrappedText = new WritableCellFormat
348       (WritableWorkbook.ARIAL_10_PT);
349     wrappedText.setWrap(true);
350
351     s.setColumnView(0, 20);
352     s.setColumnView(2, 20);
353     s.setColumnView(3, 20);
354     s.setColumnView(4, 20);
355
356     s.getSettings().setFitWidth(2);
357     s.getSettings().setFitHeight(2);
358
359     Calendar JavaDoc c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
360     c.set(1975, 4, 31, 15, 21, 45);
361     c.set(Calendar.MILLISECOND, 660);
362     Date JavaDoc date = c.getTime();
363     c.set(1900, 0, 1, 0, 0, 0);
364     c.set(Calendar.MILLISECOND, 0);
365
366     Date JavaDoc date2 = c.getTime();
367     c.set(1970, 0, 1, 0, 0, 0);
368     Date JavaDoc date3 = c.getTime();
369     c.set(1918, 10, 11, 11, 0, 0);
370     Date JavaDoc date4 = c.getTime();
371     c.set(1900, 0, 2, 0, 0, 0);
372     Date JavaDoc date5 = c.getTime();
373     c.set(1901, 0, 1, 0, 0, 0);
374     Date JavaDoc date6 = c.getTime();
375     c.set(1900, 4, 31, 0, 0, 0);
376     Date JavaDoc date7 = c.getTime();
377     c.set(1900, 1, 1, 0, 0, 0);
378     Date JavaDoc date8 = c.getTime();
379     c.set(1900, 0, 31, 0, 0, 0);
380     Date JavaDoc date9 = c.getTime();
381     c.set(1900, 2, 1, 0, 0, 0);
382     Date JavaDoc date10 = c.getTime();
383     c.set(1900, 1, 27, 0, 0, 0);
384     Date JavaDoc date11 = c.getTime();
385     c.set(1900, 1, 28, 0, 0, 0);
386     Date JavaDoc date12 = c.getTime();
387     c.set(1980, 5, 31, 12, 0, 0);
388     Date JavaDoc date13 = c.getTime();
389     c.set(1066, 9, 14, 0, 0, 0);
390     Date JavaDoc date14 = c.getTime();
391
392     // Built in date formats
393
SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("dd MMM yyyy HH:mm:ss.SSS");
394     sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
395     Label l = new Label(0,0,"All dates are " + sdf.format(date),
396                         wrappedText);
397     s.addCell(l);
398
399     l = new Label(0,1,"Built in formats",
400                   wrappedText);
401     s.addCell(l);
402
403     l = new Label(2, 1, "Custom formats");
404     s.addCell(l);
405
406     WritableCellFormat cf1 = new WritableCellFormat(DateFormats.FORMAT1);
407     DateTime dt = new DateTime(0,2,date, cf1, DateTime.GMT);
408     s.addCell(dt);
409
410     cf1 = new WritableCellFormat(DateFormats.FORMAT2);
411     dt = new DateTime(0,3,date, cf1,DateTime.GMT);
412     s.addCell(dt);
413
414     cf1 = new WritableCellFormat(DateFormats.FORMAT3);
415     dt = new DateTime(0,4,date, cf1);
416     s.addCell(dt);
417
418     cf1 = new WritableCellFormat(DateFormats.FORMAT4);
419     dt = new DateTime(0,5,date, cf1);
420     s.addCell(dt);
421
422     cf1 = new WritableCellFormat(DateFormats.FORMAT5);
423     dt = new DateTime(0,6,date, cf1);
424     s.addCell(dt);
425
426     cf1 = new WritableCellFormat(DateFormats.FORMAT6);
427     dt = new DateTime(0,7,date, cf1);
428     s.addCell(dt);
429
430     cf1 = new WritableCellFormat(DateFormats.FORMAT7);
431     dt = new DateTime(0,8,date, cf1, DateTime.GMT);
432     s.addCell(dt);
433
434     cf1 = new WritableCellFormat(DateFormats.FORMAT8);
435     dt = new DateTime(0,9,date, cf1, DateTime.GMT);
436     s.addCell(dt);
437
438     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
439     dt = new DateTime(0,10,date, cf1, DateTime.GMT);
440     s.addCell(dt);
441
442     cf1 = new WritableCellFormat(DateFormats.FORMAT10);
443     dt = new DateTime(0,11,date, cf1, DateTime.GMT);
444     s.addCell(dt);
445
446     cf1 = new WritableCellFormat(DateFormats.FORMAT11);
447     dt = new DateTime(0,12,date, cf1, DateTime.GMT);
448     s.addCell(dt);
449
450     cf1 = new WritableCellFormat(DateFormats.FORMAT12);
451     dt = new DateTime(0,13,date, cf1, DateTime.GMT);
452     s.addCell(dt);
453
454     // Custom formats
455
DateFormat JavaDoc df = new DateFormat JavaDoc("dd MM yyyy");
456     cf1 = new WritableCellFormat(df);
457     l = new Label(2, 2, "dd MM yyyy");
458     s.addCell(l);
459
460     dt = new DateTime(3, 2, date, cf1, DateTime.GMT);
461     s.addCell(dt);
462
463     df = new DateFormat JavaDoc("dd MMM yyyy");
464     cf1 = new WritableCellFormat(df);
465     l = new Label(2, 3, "dd MMM yyyy");
466     s.addCell(l);
467
468     dt = new DateTime(3, 3, date, cf1, DateTime.GMT);
469     s.addCell(dt);
470  
471     df = new DateFormat JavaDoc("hh:mm");
472     cf1 = new WritableCellFormat(df);
473     l = new Label(2, 4, "hh:mm");
474     s.addCell(l);
475
476     dt = new DateTime(3, 4, date, cf1, DateTime.GMT);
477     s.addCell(dt);
478
479     df = new DateFormat JavaDoc("hh:mm:ss");
480     cf1 = new WritableCellFormat(df);
481     l = new Label(2, 5, "hh:mm:ss");
482     s.addCell(l);
483
484     dt = new DateTime(3, 5, date, cf1, DateTime.GMT);
485     s.addCell(dt);
486
487     df = new DateFormat JavaDoc("H:mm:ss a");
488     cf1 = new WritableCellFormat(df);
489     l = new Label(2, 5, "H:mm:ss a");
490     s.addCell(l);
491
492     dt = new DateTime(3, 5, date, cf1, DateTime.GMT);
493     s.addCell(dt);
494     dt = new DateTime(4, 5, date13, cf1, DateTime.GMT);
495     s.addCell(dt);
496
497     df = new DateFormat JavaDoc("mm:ss.SSS");
498     cf1 = new WritableCellFormat(df);
499     l = new Label(2, 6, "mm:ss.SSS");
500     s.addCell(l);
501
502     dt = new DateTime(3, 6, date, cf1, DateTime.GMT);
503     s.addCell(dt);
504
505     df = new DateFormat JavaDoc("hh:mm:ss a");
506     cf1 = new WritableCellFormat(df);
507     l = new Label(2, 7, "hh:mm:ss a");
508     s.addCell(l);
509
510     dt = new DateTime(4, 7, date13, cf1, DateTime.GMT);
511     s.addCell(dt);
512
513
514     // Check out the zero date ie. 1 Jan 1900
515
l = new Label(0,16,"Zero date " + sdf.format(date2),
516                   wrappedText);
517     s.addCell(l);
518
519     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
520     dt = new DateTime(0,17,date2, cf1, DateTime.GMT);
521     s.addCell(dt);
522
523     // Check out the zero date + 1 ie. 2 Jan 1900
524
l = new Label(3,16,"Zero date + 1 " + sdf.format(date5),
525                   wrappedText);
526     s.addCell(l);
527
528     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
529     dt = new DateTime(3,17,date5, cf1, DateTime.GMT);
530     s.addCell(dt);
531
532     // Check out the 1 Jan 1901
533
l = new Label(3,19, sdf.format(date6),
534                   wrappedText);
535     s.addCell(l);
536
537     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
538     dt = new DateTime(3,20,date6, cf1, DateTime.GMT);
539     s.addCell(dt);
540
541     // Check out the 31 May 1900
542
l = new Label(3,22, sdf.format(date7),
543                   wrappedText);
544     s.addCell(l);
545
546     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
547     dt = new DateTime(3,23, date7, cf1, DateTime.GMT);
548     s.addCell(dt);
549
550     // Check out 1 Feb 1900
551
l = new Label(3,25, sdf.format(date8),
552                   wrappedText);
553     s.addCell(l);
554
555     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
556     dt = new DateTime(3,26, date8, cf1, DateTime.GMT);
557     s.addCell(dt);
558
559     // Check out 31 Jan 1900
560
l = new Label(3,28, sdf.format(date9),
561                   wrappedText);
562     s.addCell(l);
563
564     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
565     dt = new DateTime(3,29, date9, cf1, DateTime.GMT);
566     s.addCell(dt);
567
568     // Check out 31 Jan 1900
569
l = new Label(3,28, sdf.format(date9),
570                   wrappedText);
571     s.addCell(l);
572
573     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
574     dt = new DateTime(3,29, date9, cf1, DateTime.GMT);
575     s.addCell(dt);
576
577     // Check out 1 Mar 1900
578
l = new Label(3,31, sdf.format(date10),
579                   wrappedText);
580     s.addCell(l);
581
582     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
583     dt = new DateTime(3,32, date10, cf1, DateTime.GMT);
584     s.addCell(dt);
585
586     // Check out 27 Feb 1900
587
l = new Label(3,34, sdf.format(date11),
588                   wrappedText);
589     s.addCell(l);
590
591     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
592     dt = new DateTime(3,35, date11, cf1, DateTime.GMT);
593     s.addCell(dt);
594
595     // Check out 28 Feb 1900
596
l = new Label(3,37, sdf.format(date12),
597                   wrappedText);
598     s.addCell(l);
599
600     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
601     dt = new DateTime(3,38, date12, cf1, DateTime.GMT);
602     s.addCell(dt);
603
604     // Check out the zero date ie. 1 Jan 1970
605
l = new Label(0,19,"Zero UTC date " + sdf.format(date3),
606                   wrappedText);
607     s.addCell(l);
608
609     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
610     dt = new DateTime(0,20,date3, cf1, DateTime.GMT);
611     s.addCell(dt);
612
613     // Check out the WWI armistice day ie. 11 am, Nov 11, 1918
614
l = new Label(0,22,"Armistice date " + sdf.format(date4),
615                   wrappedText);
616     s.addCell(l);
617
618     cf1 = new WritableCellFormat(DateFormats.FORMAT9);
619     dt = new DateTime(0,23,date4, cf1, DateTime.GMT);
620     s.addCell(dt);
621
622     // Check out the Battle of Hastings date Oct 14th, 1066
623
l = new Label(0,25, "Battle of Hastings " + sdf.format(date14),
624                   wrappedText);
625     s.addCell(l);
626
627     cf1 = new WritableCellFormat(DateFormats.FORMAT2);
628     dt = new DateTime(0, 26, date14, cf1, DateTime.GMT);
629     s.addCell(dt);
630   }
631
632   /**
633    * Adds cells to the specified sheet which test the various label formatting
634    * styles, such as different fonts, different sizes and bold, underline etc.
635    *
636    * @param s1
637    */

638   private void writeLabelFormatSheet(WritableSheet s1) throws WriteException
639   {
640     s1.setColumnView(0, 60);
641
642     Label lr = new Label(0,0, "Arial Fonts");
643     s1.addCell(lr);
644
645     lr = new Label(1,0, "10pt");
646     s1.addCell(lr);
647
648     lr = new Label(2, 0, "Normal");
649     s1.addCell(lr);
650
651     lr = new Label(3, 0, "12pt");
652     s1.addCell(lr);
653
654     WritableFont arial12pt = new WritableFont(WritableFont.ARIAL, 12);
655     WritableCellFormat arial12format = new WritableCellFormat(arial12pt);
656     arial12format.setWrap(true);
657     lr = new Label(4, 0, "Normal", arial12format);
658     s1.addCell(lr);
659
660     WritableFont arial10ptBold = new WritableFont
661       (WritableFont.ARIAL, 10, WritableFont.BOLD);
662     WritableCellFormat arial10BoldFormat = new WritableCellFormat
663       (arial10ptBold);
664     lr = new Label(2, 2, "BOLD", arial10BoldFormat);
665     s1.addCell(lr);
666
667     WritableFont arial12ptBold = new WritableFont
668       (WritableFont.ARIAL, 12, WritableFont.BOLD);
669     WritableCellFormat arial12BoldFormat = new WritableCellFormat
670       (arial12ptBold);
671     lr = new Label(4, 2, "BOLD", arial12BoldFormat);
672     s1.addCell(lr);
673
674     WritableFont arial10ptItalic = new WritableFont
675       (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, true);
676     WritableCellFormat arial10ItalicFormat = new WritableCellFormat
677       (arial10ptItalic);
678     lr = new Label(2, 4, "Italic", arial10ItalicFormat);
679     s1.addCell(lr);
680
681     WritableFont arial12ptItalic = new WritableFont
682       (WritableFont.ARIAL, 12, WritableFont.NO_BOLD, true);
683     WritableCellFormat arial12ptItalicFormat = new WritableCellFormat
684       (arial12ptItalic);
685     lr = new Label(4, 4, "Italic", arial12ptItalicFormat);
686     s1.addCell(lr);
687
688     WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
689     WritableCellFormat times10format = new WritableCellFormat(times10pt);
690     lr = new Label(0, 7, "Times Fonts", times10format);
691     s1.addCell(lr);
692
693     lr = new Label(1, 7, "10pt", times10format);
694     s1.addCell(lr);
695
696     lr = new Label(2, 7, "Normal", times10format);
697     s1.addCell(lr);
698
699     lr = new Label(3, 7, "12pt", times10format);
700     s1.addCell(lr);
701
702     WritableFont times12pt = new WritableFont(WritableFont.TIMES, 12);
703     WritableCellFormat times12format = new WritableCellFormat(times12pt);
704     lr = new Label(4, 7, "Normal", times12format);
705     s1.addCell(lr);
706
707     WritableFont times10ptBold = new WritableFont
708       (WritableFont.TIMES, 10, WritableFont.BOLD);
709     WritableCellFormat times10BoldFormat = new WritableCellFormat
710       (times10ptBold);
711     lr = new Label(2, 9, "BOLD", times10BoldFormat);
712     s1.addCell(lr);
713
714     WritableFont times12ptBold = new WritableFont
715       (WritableFont.TIMES, 12, WritableFont.BOLD);
716     WritableCellFormat times12BoldFormat = new WritableCellFormat
717       (times12ptBold);
718     lr = new Label(4, 9, "BOLD", times12BoldFormat);
719     s1.addCell(lr);
720
721     // The underline styles
722
s1.setColumnView(6, 22);
723     s1.setColumnView(7, 22);
724     s1.setColumnView(8, 22);
725     s1.setColumnView(9, 22);
726
727     lr = new Label(0, 11, "Underlining");
728     s1.addCell(lr);
729
730     WritableFont arial10ptUnderline = new WritableFont
731       (WritableFont.ARIAL,
732        WritableFont.DEFAULT_POINT_SIZE,
733        WritableFont.NO_BOLD,
734        false,
735        UnderlineStyle.SINGLE);
736     WritableCellFormat arialUnderline = new WritableCellFormat
737       (arial10ptUnderline);
738     lr = new Label(6,11, "Underline", arialUnderline);
739     s1.addCell(lr);
740
741     WritableFont arial10ptDoubleUnderline = new WritableFont
742       (WritableFont.ARIAL,
743        WritableFont.DEFAULT_POINT_SIZE,
744        WritableFont.NO_BOLD,
745        false,
746        UnderlineStyle.DOUBLE);
747     WritableCellFormat arialDoubleUnderline = new WritableCellFormat
748       (arial10ptDoubleUnderline);
749     lr = new Label(7,11, "Double Underline", arialDoubleUnderline);
750     s1.addCell(lr);
751
752     WritableFont arial10ptSingleAcc = new WritableFont
753       (WritableFont.ARIAL,
754        WritableFont.DEFAULT_POINT_SIZE,
755        WritableFont.NO_BOLD,
756        false,
757        UnderlineStyle.SINGLE_ACCOUNTING);
758     WritableCellFormat arialSingleAcc = new WritableCellFormat
759       (arial10ptSingleAcc);
760     lr = new Label(8,11, "Single Accounting Underline", arialSingleAcc);
761     s1.addCell(lr);
762
763     WritableFont arial10ptDoubleAcc = new WritableFont
764       (WritableFont.ARIAL,
765        WritableFont.DEFAULT_POINT_SIZE,
766        WritableFont.NO_BOLD,
767        false,
768        UnderlineStyle.DOUBLE_ACCOUNTING);
769     WritableCellFormat arialDoubleAcc = new WritableCellFormat
770       (arial10ptDoubleAcc);
771     lr = new Label(9,11, "Double Accounting Underline", arialDoubleAcc);
772     s1.addCell(lr);
773
774     WritableFont times14ptBoldUnderline = new WritableFont
775       (WritableFont.TIMES,
776        14,
777        WritableFont.BOLD,
778        false,
779        UnderlineStyle.SINGLE);
780     WritableCellFormat timesBoldUnderline = new WritableCellFormat
781       (times14ptBoldUnderline);
782     lr = new Label(6,12, "Times 14 Bold Underline", timesBoldUnderline);
783     s1.addCell(lr);
784
785     WritableFont arial18ptBoldItalicUnderline = new WritableFont
786       (WritableFont.ARIAL,
787        18,
788        WritableFont.BOLD,
789        true,
790        UnderlineStyle.SINGLE);
791     WritableCellFormat arialBoldItalicUnderline = new WritableCellFormat
792       (arial18ptBoldItalicUnderline);
793     lr = new Label(6,13, "Arial 18 Bold Italic Underline",
794                    arialBoldItalicUnderline);
795     s1.addCell(lr);
796
797     lr = new Label(0, 15, "Script styles");
798     s1.addCell(lr);
799
800     WritableFont superscript = new WritableFont
801       (WritableFont.ARIAL,
802        WritableFont.DEFAULT_POINT_SIZE,
803        WritableFont.NO_BOLD,
804        false,
805        UnderlineStyle.NO_UNDERLINE,
806        Colour.BLACK,
807        ScriptStyle.SUPERSCRIPT);
808     WritableCellFormat superscriptFormat = new WritableCellFormat
809       (superscript);
810