001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.usermodel.examples;
019:
020: import org.apache.poi.hssf.usermodel.HSSFSheet;
021: import org.apache.poi.hssf.usermodel.HSSFWorkbook;
022: import org.apache.poi.hssf.usermodel.HSSFRow;
023: import org.apache.poi.hssf.usermodel.HSSFCell;
024:
025: import java.io.FileOutputStream;
026: import java.io.IOException;
027:
028: /**
029: * Creates outlines.
030: *
031: * @author Glen Stampoultzis (glens at apache.org)
032: */
033: public class Outlines {
034: private Outlines() {
035: }
036:
037: public static void main(String[] args) throws IOException {
038: createCase1("outline1.xls");
039: System.out
040: .println("outline1.xls written. Two expanded groups.");
041: createCase2("outline2.xls");
042: System.out
043: .println("outline2.xls written. Two groups. Inner group collapsed.");
044: createCase3("outline3.xls");
045: System.out
046: .println("outline3.xls written. Two groups. Both collapsed.");
047: createCase4("outline4.xls");
048: System.out
049: .println("outline4.xls written. Two groups. Collapsed then inner group expanded.");
050: createCase5("outline5.xls");
051: System.out
052: .println("outline5.xls written. Two groups. Collapsed then reexpanded.");
053: createCase6("outline6.xls");
054: System.out
055: .println("outline6.xls written. Two groups with matching end points. Second group collapsed.");
056: createCase7("outline7.xls");
057: System.out.println("outline7.xls written. Row outlines.");
058: createCase8("outline8.xls");
059: System.out
060: .println("outline8.xls written. Row outlines. Inner group collapsed.");
061: createCase9("outline9.xls");
062: System.out
063: .println("outline9.xls written. Row outlines. Both collapsed.");
064: createCase10("outline10.xls");
065: System.out
066: .println("outline10.xls written. Row outlines. Collapsed then inner group expanded.");
067: createCase11("outline11.xls");
068: System.out
069: .println("outline11.xls written. Row outlines. Collapsed then expanded.");
070: createCase12("outline12.xls");
071: System.out
072: .println("outline12.xls written. Row outlines. Two row groups with matching end points. Second group collapsed.");
073: createCase13("outline13.xls");
074: System.out.println("outline13.xls written. Mixed bag.");
075: }
076:
077: private static void createCase1(String filename) throws IOException {
078: HSSFWorkbook wb = new HSSFWorkbook();
079: HSSFSheet sheet1 = wb.createSheet("new sheet");
080:
081: sheet1.groupColumn((short) 4, (short) 7);
082:
083: for (int row = 0; row < 200; row++) {
084: HSSFRow r = sheet1.createRow(row);
085: for (int column = 0; column < 200; column++) {
086: HSSFCell c = r.createCell((short) column);
087: c.setCellValue(column);
088: }
089: }
090:
091: FileOutputStream fileOut = new FileOutputStream(filename);
092: wb.write(fileOut);
093: fileOut.close();
094: }
095:
096: private static void createCase2(String filename) throws IOException {
097: HSSFWorkbook wb = new HSSFWorkbook();
098: HSSFSheet sheet1 = wb.createSheet("new sheet");
099:
100: sheet1.groupColumn((short) 2, (short) 10);
101: sheet1.groupColumn((short) 4, (short) 7);
102: sheet1.setColumnGroupCollapsed((short) 4, true);
103:
104: FileOutputStream fileOut = new FileOutputStream(filename);
105: wb.write(fileOut);
106: fileOut.close();
107: }
108:
109: private static void createCase3(String filename) throws IOException {
110: HSSFWorkbook wb = new HSSFWorkbook();
111: HSSFSheet sheet1 = wb.createSheet("new sheet");
112:
113: sheet1.groupColumn((short) 2, (short) 10);
114: sheet1.groupColumn((short) 4, (short) 7);
115: sheet1.setColumnGroupCollapsed((short) 4, true);
116: sheet1.setColumnGroupCollapsed((short) 2, true);
117:
118: FileOutputStream fileOut = new FileOutputStream(filename);
119: wb.write(fileOut);
120: fileOut.close();
121: }
122:
123: private static void createCase4(String filename) throws IOException {
124: HSSFWorkbook wb = new HSSFWorkbook();
125: HSSFSheet sheet1 = wb.createSheet("new sheet");
126:
127: sheet1.groupColumn((short) 2, (short) 10);
128: sheet1.groupColumn((short) 4, (short) 7);
129: sheet1.setColumnGroupCollapsed((short) 4, true);
130: sheet1.setColumnGroupCollapsed((short) 2, true);
131:
132: sheet1.setColumnGroupCollapsed((short) 4, false);
133:
134: FileOutputStream fileOut = new FileOutputStream(filename);
135: wb.write(fileOut);
136: fileOut.close();
137: }
138:
139: private static void createCase5(String filename) throws IOException {
140: HSSFWorkbook wb = new HSSFWorkbook();
141: HSSFSheet sheet1 = wb.createSheet("new sheet");
142:
143: sheet1.groupColumn((short) 2, (short) 10);
144: sheet1.groupColumn((short) 4, (short) 7);
145: sheet1.setColumnGroupCollapsed((short) 4, true);
146: sheet1.setColumnGroupCollapsed((short) 2, true);
147:
148: sheet1.setColumnGroupCollapsed((short) 4, false);
149: sheet1.setColumnGroupCollapsed((short) 3, false);
150:
151: FileOutputStream fileOut = new FileOutputStream(filename);
152: wb.write(fileOut);
153: fileOut.close();
154: }
155:
156: private static void createCase6(String filename) throws IOException {
157: HSSFWorkbook wb = new HSSFWorkbook();
158: HSSFSheet sheet1 = wb.createSheet("new sheet");
159:
160: sheet1.groupColumn((short) 2, (short) 10);
161: sheet1.groupColumn((short) 4, (short) 10);
162: sheet1.setColumnGroupCollapsed((short) 4, true);
163: sheet1.setColumnGroupCollapsed((short) 2, true);
164:
165: sheet1.setColumnGroupCollapsed((short) 3, false);
166:
167: FileOutputStream fileOut = new FileOutputStream(filename);
168: wb.write(fileOut);
169: fileOut.close();
170: }
171:
172: private static void createCase7(String filename) throws IOException {
173: HSSFWorkbook wb = new HSSFWorkbook();
174: HSSFSheet sheet1 = wb.createSheet("new sheet");
175:
176: sheet1.groupRow(5, 14);
177: sheet1.groupRow(7, 10);
178:
179: FileOutputStream fileOut = new FileOutputStream(filename);
180: wb.write(fileOut);
181: fileOut.close();
182: }
183:
184: private static void createCase8(String filename) throws IOException {
185: HSSFWorkbook wb = new HSSFWorkbook();
186: HSSFSheet sheet1 = wb.createSheet("new sheet");
187:
188: sheet1.groupRow(5, 14);
189: sheet1.groupRow(7, 10);
190: sheet1.setRowGroupCollapsed(7, true);
191:
192: FileOutputStream fileOut = new FileOutputStream(filename);
193: wb.write(fileOut);
194: fileOut.close();
195: }
196:
197: private static void createCase9(String filename) throws IOException {
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 fileOut = new FileOutputStream(filename);
207: wb.write(fileOut);
208: fileOut.close();
209: }
210:
211: private static void createCase10(String filename)
212: throws IOException {
213: HSSFWorkbook wb = new HSSFWorkbook();
214: HSSFSheet sheet1 = wb.createSheet("new sheet");
215:
216: sheet1.groupRow(5, 14);
217: sheet1.groupRow(7, 10);
218: sheet1.setRowGroupCollapsed(7, true);
219: sheet1.setRowGroupCollapsed(5, true);
220: sheet1.setRowGroupCollapsed(8, false);
221:
222: FileOutputStream fileOut = new FileOutputStream(filename);
223: wb.write(fileOut);
224: fileOut.close();
225: }
226:
227: private static void createCase11(String filename)
228: throws IOException {
229: HSSFWorkbook wb = new HSSFWorkbook();
230: HSSFSheet sheet1 = wb.createSheet("new sheet");
231:
232: sheet1.groupRow(5, 14);
233: sheet1.groupRow(7, 10);
234: sheet1.setRowGroupCollapsed(7, true);
235: sheet1.setRowGroupCollapsed(5, true);
236: sheet1.setRowGroupCollapsed(8, false);
237: sheet1.setRowGroupCollapsed(14, false);
238:
239: FileOutputStream fileOut = new FileOutputStream(filename);
240: wb.write(fileOut);
241: fileOut.close();
242: }
243:
244: private static void createCase12(String filename)
245: throws IOException {
246: HSSFWorkbook wb = new HSSFWorkbook();
247: HSSFSheet sheet1 = wb.createSheet("new sheet");
248:
249: sheet1.groupRow(5, 14);
250: sheet1.groupRow(7, 14);
251: sheet1.setRowGroupCollapsed(7, true);
252: sheet1.setRowGroupCollapsed(5, true);
253: sheet1.setRowGroupCollapsed(6, false);
254:
255: FileOutputStream fileOut = new FileOutputStream(filename);
256: wb.write(fileOut);
257: fileOut.close();
258: }
259:
260: private static void createCase13(String filename)
261: throws IOException {
262: HSSFWorkbook wb = new HSSFWorkbook();
263: HSSFSheet sheet1 = wb.createSheet("new sheet");
264:
265: sheet1.groupRow(5, 14);
266: sheet1.groupRow(7, 14);
267: sheet1.groupRow(16, 19);
268:
269: sheet1.groupColumn((short) 4, (short) 7);
270: sheet1.groupColumn((short) 9, (short) 12);
271: sheet1.groupColumn((short) 10, (short) 11);
272:
273: FileOutputStream fileOut = new FileOutputStream(filename);
274: wb.write(fileOut);
275: fileOut.close();
276: }
277:
278: }
|