123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- /* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ==================================================================== */
-
- package org.apache.poi.examples.hssf.usermodel;
-
- import java.io.Closeable;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.lang.reflect.InvocationTargetException;
-
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import org.apache.poi.hssf.usermodel.HSSFCell;
- import org.apache.poi.hssf.usermodel.HSSFRow;
- import org.apache.poi.hssf.usermodel.HSSFSheet;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
- /**
- * Creates outlines.
- */
- public class Outlines implements Closeable {
- public static void main(String[] args)
- throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
- Logger LOGGER = LogManager.getLogger(Outlines.class);
- for (int i=1; i<=13; i++) {
- try (Outlines o = new Outlines()) {
- String log = (String) Outlines.class.getDeclaredMethod("test" + i).invoke(o);
- String filename = "outline" + i + ".xls";
- o.writeOut(filename);
- LOGGER.atInfo().log("{} written. {}", filename, log);
- }
- }
- }
-
- private final HSSFWorkbook wb = new HSSFWorkbook();
- private final HSSFSheet sheet1 = wb.createSheet("new sheet");
-
- public void writeOut(String filename) throws IOException {
- try (FileOutputStream fileOut = new FileOutputStream(filename)) {
- wb.write(fileOut);
- }
- }
-
- @Override
- public void close() throws IOException {
- wb.close();
- }
-
- public String test1() {
- sheet1.groupColumn(4, 7);
-
- for (int row = 0; row < 200; row++) {
- HSSFRow r = sheet1.createRow(row);
- for (int column = 0; column < 200; column++) {
- HSSFCell c = r.createCell(column);
- c.setCellValue(column);
- }
- }
- return "Two expanded groups.";
- }
-
- public String test2() {
- sheet1.groupColumn(2, 10);
- sheet1.groupColumn(4, 7);
- sheet1.setColumnGroupCollapsed(4, true);
- return "Two groups. Inner group collapsed.";
- }
-
- public String test3() {
- sheet1.groupColumn(2, 10);
- sheet1.groupColumn(4, 7);
- sheet1.setColumnGroupCollapsed(4, true);
- sheet1.setColumnGroupCollapsed(2, true);
- return "Two groups. Both collapsed.";
- }
-
- public String test4() {
- sheet1.groupColumn(2, 10);
- sheet1.groupColumn(4, 7);
- sheet1.setColumnGroupCollapsed(4, true);
- sheet1.setColumnGroupCollapsed(2, true);
-
- sheet1.setColumnGroupCollapsed(4, false);
- return "Two groups. Collapsed then inner group expanded.";
- }
-
- public String test5() {
- sheet1.groupColumn(2, 10);
- sheet1.groupColumn(4, 7);
- sheet1.setColumnGroupCollapsed(4, true);
- sheet1.setColumnGroupCollapsed(2, true);
-
- sheet1.setColumnGroupCollapsed(4, false);
- sheet1.setColumnGroupCollapsed(3, false);
- return "Two groups. Collapsed then reexpanded.";
- }
-
- public String test6() {
- sheet1.groupColumn(2, 10);
- sheet1.groupColumn(4, 10);
- sheet1.setColumnGroupCollapsed(4, true);
- sheet1.setColumnGroupCollapsed(2, true);
-
- sheet1.setColumnGroupCollapsed(3, false);
- return "Two groups with matching end points. Second group collapsed.";
- }
-
- public String test7() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 10);
- return "Row outlines.";
- }
-
- public String test8() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 10);
- sheet1.setRowGroupCollapsed(7, true);
- return "Row outlines. Inner group collapsed.";
- }
-
- public String test9() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 10);
- sheet1.setRowGroupCollapsed(7, true);
- sheet1.setRowGroupCollapsed(5, true);
- return "Row outlines. Both collapsed.";
- }
-
- public String test10() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 10);
- sheet1.setRowGroupCollapsed(7, true);
- sheet1.setRowGroupCollapsed(5, true);
- sheet1.setRowGroupCollapsed(8, false);
- return "Row outlines. Collapsed then inner group expanded.";
- }
-
- public String test11() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 10);
- sheet1.setRowGroupCollapsed(7, true);
- sheet1.setRowGroupCollapsed(5, true);
- sheet1.setRowGroupCollapsed(8, false);
- sheet1.setRowGroupCollapsed(14, false);
- return "Row outlines. Collapsed then expanded.";
- }
-
- public String test12() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 14);
- sheet1.setRowGroupCollapsed(7, true);
- sheet1.setRowGroupCollapsed(5, true);
- sheet1.setRowGroupCollapsed(6, false);
- return "Row outlines. Two row groups with matching end points. Second group collapsed.";
- }
-
- public String test13() {
- sheet1.groupRow(5, 14);
- sheet1.groupRow(7, 14);
- sheet1.groupRow(16, 19);
-
- sheet1.groupColumn(4, 7);
- sheet1.groupColumn(9, 12);
- sheet1.groupColumn(10, 11);
- return "Mixed bag.";
- }
- }
|