KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > examples > Outlines


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.usermodel.examples;
20
21 import org.apache.poi.hssf.usermodel.HSSFSheet;
22 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
23 import org.apache.poi.hssf.usermodel.HSSFRow;
24 import org.apache.poi.hssf.usermodel.HSSFCell;
25
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 /**
30  * Creates outlines.
31  *
32  * @author Glen Stampoultzis (glens at apache.org)
33  */

34 public class Outlines
35 {
36     private Outlines(){}
37
38     public static void main(String JavaDoc[] args)
39         throws IOException JavaDoc
40     {
41         createCase1( "outline1.xls" );
42         System.out.println( "outline1.xls written. Two expanded groups." );
43         createCase2( "outline2.xls" );
44         System.out.println( "outline2.xls written. Two groups. Inner group collapsed." );
45         createCase3( "outline3.xls" );
46         System.out.println( "outline3.xls written. Two groups. Both collapsed." );
47         createCase4( "outline4.xls" );
48         System.out.println( "outline4.xls written. Two groups. Collapsed then inner group expanded." );
49         createCase5( "outline5.xls" );
50         System.out.println( "outline5.xls written. Two groups. Collapsed then reexpanded." );
51         createCase6( "outline6.xls" );
52         System.out.println( "outline6.xls written. Two groups with matching end points. Second group collapsed." );
53         createCase7( "outline7.xls" );
54         System.out.println( "outline7.xls written. Row outlines." );
55         createCase8( "outline8.xls" );
56         System.out.println( "outline8.xls written. Row outlines. Inner group collapsed." );
57         createCase9( "outline9.xls" );
58         System.out.println( "outline9.xls written. Row outlines. Both collapsed." );
59         createCase10( "outline10.xls" );
60         System.out.println( "outline10.xls written. Row outlines. Collapsed then inner group expanded." );
61         createCase11( "outline11.xls" );
62         System.out.println( "outline11.xls written. Row outlines. Collapsed then expanded." );
63         createCase12( "outline12.xls" );
64         System.out.println( "outline12.xls written. Row outlines. Two row groups with matching end points. Second group collapsed." );
65         createCase13( "outline13.xls" );
66         System.out.println( "outline13.xls written. Mixed bag." );
67     }
68
69     private static void createCase1( String JavaDoc filename ) throws IOException JavaDoc{
70         HSSFWorkbook wb = new HSSFWorkbook();
71         HSSFSheet sheet1 = wb.createSheet("new sheet");
72
73         sheet1.groupColumn( (short)4, (short)7 );
74
75         for (int row = 0; row < 200; row++)
76         {
77             HSSFRow r = sheet1.createRow( row );
78             for (int column = 0; column < 200; column++)
79             {
80                 HSSFCell c = r.createCell( (short) column );
81                 c.setCellValue( column );
82             }
83         }
84
85         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
86         wb.write(fileOut);
87         fileOut.close();
88     }
89
90     private static void createCase2( String JavaDoc filename ) throws IOException JavaDoc{
91         HSSFWorkbook wb = new HSSFWorkbook();
92         HSSFSheet sheet1 = wb.createSheet("new sheet");
93
94         sheet1.groupColumn( (short)2, (short)10 );
95         sheet1.groupColumn( (short)4, (short)7 );
96         sheet1.setColumnGroupCollapsed( (short)4, true );
97
98         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
99         wb.write(fileOut);
100         fileOut.close();
101     }
102
103     private static void createCase3( String JavaDoc filename ) throws IOException JavaDoc{
104         HSSFWorkbook wb = new HSSFWorkbook();
105         HSSFSheet sheet1 = wb.createSheet("new sheet");
106
107         sheet1.groupColumn( (short)2, (short)10 );
108         sheet1.groupColumn( (short)4, (short)7 );
109         sheet1.setColumnGroupCollapsed( (short)4, true );
110         sheet1.setColumnGroupCollapsed( (short)2, true );
111
112         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
113         wb.write(fileOut);
114         fileOut.close();
115     }
116
117     private static void createCase4( String JavaDoc filename ) throws IOException JavaDoc{
118         HSSFWorkbook wb = new HSSFWorkbook();
119         HSSFSheet sheet1 = wb.createSheet("new sheet");
120
121         sheet1.groupColumn( (short)2, (short)10 );
122         sheet1.groupColumn( (short)4, (short)7 );
123         sheet1.setColumnGroupCollapsed( (short)4, true );
124         sheet1.setColumnGroupCollapsed( (short)2, true );
125
126         sheet1.setColumnGroupCollapsed( (short)4, false );
127
128         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
129         wb.write(fileOut);
130         fileOut.close();
131     }
132
133     private static void createCase5( String JavaDoc filename ) throws IOException JavaDoc{
134         HSSFWorkbook wb = new HSSFWorkbook();
135         HSSFSheet sheet1 = wb.createSheet("new sheet");
136
137         sheet1.groupColumn( (short)2, (short)10 );
138         sheet1.groupColumn( (short)4, (short)7 );
139         sheet1.setColumnGroupCollapsed( (short)4, true );
140         sheet1.setColumnGroupCollapsed( (short)2, true );
141
142         sheet1.setColumnGroupCollapsed( (short)4, false );
143         sheet1.setColumnGroupCollapsed( (short)3, false );
144
145         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
146         wb.write(fileOut);
147         fileOut.close();
148     }
149
150     private static void createCase6( String JavaDoc filename ) throws IOException JavaDoc{
151         HSSFWorkbook wb = new HSSFWorkbook();
152         HSSFSheet sheet1 = wb.createSheet("new sheet");
153
154         sheet1.groupColumn( (short)2, (short)10 );
155         sheet1.groupColumn( (short)4, (short)10 );
156         sheet1.setColumnGroupCollapsed( (short)4, true );
157         sheet1.setColumnGroupCollapsed( (short)2, true );
158
159         sheet1.setColumnGroupCollapsed( (short)3, false );
160
161         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
162         wb.write(fileOut);
163         fileOut.close();
164     }
165
166     private static void createCase7( String JavaDoc filename )
167             throws IOException JavaDoc
168     {
169         HSSFWorkbook wb = new HSSFWorkbook();
170         HSSFSheet sheet1 = wb.createSheet("new sheet");
171
172         sheet1.groupRow( 5, 14 );
173         sheet1.groupRow( 7, 10 );
174
175         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
176         wb.write(fileOut);
177         fileOut.close();
178     }
179
180     private static void createCase8( String JavaDoc filename )
181             throws IOException JavaDoc
182     {
183         HSSFWorkbook wb = new HSSFWorkbook();
184         HSSFSheet sheet1 = wb.createSheet("new sheet");
185
186         sheet1.groupRow( 5, 14 );
187         sheet1.groupRow( 7, 10 );
188         sheet1.setRowGroupCollapsed( 7, true );
189
190         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
191         wb.write(fileOut);
192         fileOut.close();
193     }
194
195     private static void createCase9( String JavaDoc filename )
196             throws IOException JavaDoc
197     {
198         HSSFWorkbook wb = new HSSFWorkbook();
199         HSSFSheet sheet1 = wb.createSheet("new sheet");
200
201         sheet1.groupRow( 5, 14 );
202         sheet1.groupRow( 7, 10 );
203         sheet1.setRowGroupCollapsed( 7, true );
204         sheet1.setRowGroupCollapsed( 5, true );
205
206         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
207         wb.write(fileOut);
208         fileOut.close();
209     }
210
211
212     private static void createCase10( String JavaDoc filename )
213             throws IOException JavaDoc
214     {
215         HSSFWorkbook wb = new HSSFWorkbook();
216         HSSFSheet sheet1 = wb.createSheet("new sheet");
217
218         sheet1.groupRow( 5, 14 );
219         sheet1.groupRow( 7, 10 );
220         sheet1.setRowGroupCollapsed( 7, true );
221         sheet1.setRowGroupCollapsed( 5, true );
222         sheet1.setRowGroupCollapsed( 8, false );
223
224         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
225         wb.write(fileOut);
226         fileOut.close();
227     }
228
229     private static void createCase11( String JavaDoc filename )
230             throws IOException JavaDoc
231     {
232         HSSFWorkbook wb = new HSSFWorkbook();
233         HSSFSheet sheet1 = wb.createSheet("new sheet");
234
235         sheet1.groupRow( 5, 14 );
236         sheet1.groupRow( 7, 10 );
237         sheet1.setRowGroupCollapsed( 7, true );
238         sheet1.setRowGroupCollapsed( 5, true );
239         sheet1.setRowGroupCollapsed( 8, false );
240         sheet1.setRowGroupCollapsed( 14, false );
241
242         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
243         wb.write(fileOut);
244         fileOut.close();
245     }
246
247     private static void createCase12( String JavaDoc filename )
248             throws IOException JavaDoc
249     {
250         HSSFWorkbook wb = new HSSFWorkbook();
251         HSSFSheet sheet1 = wb.createSheet("new sheet");
252
253         sheet1.groupRow( 5, 14 );
254         sheet1.groupRow( 7, 14 );
255         sheet1.setRowGroupCollapsed( 7, true );
256         sheet1.setRowGroupCollapsed( 5, true );
257         sheet1.setRowGroupCollapsed( 6, false );
258
259         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
260         wb.write(fileOut);
261         fileOut.close();
262     }
263
264     private static void createCase13( String JavaDoc filename )
265             throws IOException JavaDoc
266     {
267         HSSFWorkbook wb = new HSSFWorkbook();
268         HSSFSheet sheet1 = wb.createSheet("new sheet");
269
270         sheet1.groupRow( 5, 14 );
271         sheet1.groupRow( 7, 14 );
272         sheet1.groupRow( 16, 19 );
273
274         sheet1.groupColumn( (short)4, (short)7 );
275         sheet1.groupColumn( (short)9, (short)12 );
276         sheet1.groupColumn( (short)10, (short)11 );
277
278         FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(filename);
279         wb.write(fileOut);
280         fileOut.close();
281     }
282
283
284 }
285
Popular Tags