You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Outlines.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.examples.hssf.usermodel;
  16. import java.io.Closeable;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.lang.reflect.InvocationTargetException;
  20. import org.apache.logging.log4j.LogManager;
  21. import org.apache.logging.log4j.Logger;
  22. import org.apache.poi.hssf.usermodel.HSSFCell;
  23. import org.apache.poi.hssf.usermodel.HSSFRow;
  24. import org.apache.poi.hssf.usermodel.HSSFSheet;
  25. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  26. /**
  27. * Creates outlines.
  28. */
  29. public class Outlines implements Closeable {
  30. public static void main(String[] args)
  31. throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
  32. Logger LOGGER = LogManager.getLogger(Outlines.class);
  33. for (int i=1; i<=13; i++) {
  34. try (Outlines o = new Outlines()) {
  35. String log = (String) Outlines.class.getDeclaredMethod("test" + i).invoke(o);
  36. String filename = "outline" + i + ".xls";
  37. o.writeOut(filename);
  38. LOGGER.atInfo().log("{} written. {}", filename, log);
  39. }
  40. }
  41. }
  42. private final HSSFWorkbook wb = new HSSFWorkbook();
  43. private final HSSFSheet sheet1 = wb.createSheet("new sheet");
  44. public void writeOut(String filename) throws IOException {
  45. try (FileOutputStream fileOut = new FileOutputStream(filename)) {
  46. wb.write(fileOut);
  47. }
  48. }
  49. @Override
  50. public void close() throws IOException {
  51. wb.close();
  52. }
  53. public String test1() {
  54. sheet1.groupColumn(4, 7);
  55. for (int row = 0; row < 200; row++) {
  56. HSSFRow r = sheet1.createRow(row);
  57. for (int column = 0; column < 200; column++) {
  58. HSSFCell c = r.createCell(column);
  59. c.setCellValue(column);
  60. }
  61. }
  62. return "Two expanded groups.";
  63. }
  64. public String test2() {
  65. sheet1.groupColumn(2, 10);
  66. sheet1.groupColumn(4, 7);
  67. sheet1.setColumnGroupCollapsed(4, true);
  68. return "Two groups. Inner group collapsed.";
  69. }
  70. public String test3() {
  71. sheet1.groupColumn(2, 10);
  72. sheet1.groupColumn(4, 7);
  73. sheet1.setColumnGroupCollapsed(4, true);
  74. sheet1.setColumnGroupCollapsed(2, true);
  75. return "Two groups. Both collapsed.";
  76. }
  77. public String test4() {
  78. sheet1.groupColumn(2, 10);
  79. sheet1.groupColumn(4, 7);
  80. sheet1.setColumnGroupCollapsed(4, true);
  81. sheet1.setColumnGroupCollapsed(2, true);
  82. sheet1.setColumnGroupCollapsed(4, false);
  83. return "Two groups. Collapsed then inner group expanded.";
  84. }
  85. public String test5() {
  86. sheet1.groupColumn(2, 10);
  87. sheet1.groupColumn(4, 7);
  88. sheet1.setColumnGroupCollapsed(4, true);
  89. sheet1.setColumnGroupCollapsed(2, true);
  90. sheet1.setColumnGroupCollapsed(4, false);
  91. sheet1.setColumnGroupCollapsed(3, false);
  92. return "Two groups. Collapsed then reexpanded.";
  93. }
  94. public String test6() {
  95. sheet1.groupColumn(2, 10);
  96. sheet1.groupColumn(4, 10);
  97. sheet1.setColumnGroupCollapsed(4, true);
  98. sheet1.setColumnGroupCollapsed(2, true);
  99. sheet1.setColumnGroupCollapsed(3, false);
  100. return "Two groups with matching end points. Second group collapsed.";
  101. }
  102. public String test7() {
  103. sheet1.groupRow(5, 14);
  104. sheet1.groupRow(7, 10);
  105. return "Row outlines.";
  106. }
  107. public String test8() {
  108. sheet1.groupRow(5, 14);
  109. sheet1.groupRow(7, 10);
  110. sheet1.setRowGroupCollapsed(7, true);
  111. return "Row outlines. Inner group collapsed.";
  112. }
  113. public String test9() {
  114. sheet1.groupRow(5, 14);
  115. sheet1.groupRow(7, 10);
  116. sheet1.setRowGroupCollapsed(7, true);
  117. sheet1.setRowGroupCollapsed(5, true);
  118. return "Row outlines. Both collapsed.";
  119. }
  120. public String test10() {
  121. sheet1.groupRow(5, 14);
  122. sheet1.groupRow(7, 10);
  123. sheet1.setRowGroupCollapsed(7, true);
  124. sheet1.setRowGroupCollapsed(5, true);
  125. sheet1.setRowGroupCollapsed(8, false);
  126. return "Row outlines. Collapsed then inner group expanded.";
  127. }
  128. public String test11() {
  129. sheet1.groupRow(5, 14);
  130. sheet1.groupRow(7, 10);
  131. sheet1.setRowGroupCollapsed(7, true);
  132. sheet1.setRowGroupCollapsed(5, true);
  133. sheet1.setRowGroupCollapsed(8, false);
  134. sheet1.setRowGroupCollapsed(14, false);
  135. return "Row outlines. Collapsed then expanded.";
  136. }
  137. public String test12() {
  138. sheet1.groupRow(5, 14);
  139. sheet1.groupRow(7, 14);
  140. sheet1.setRowGroupCollapsed(7, true);
  141. sheet1.setRowGroupCollapsed(5, true);
  142. sheet1.setRowGroupCollapsed(6, false);
  143. return "Row outlines. Two row groups with matching end points. Second group collapsed.";
  144. }
  145. public String test13() {
  146. sheet1.groupRow(5, 14);
  147. sheet1.groupRow(7, 14);
  148. sheet1.groupRow(16, 19);
  149. sheet1.groupColumn(4, 7);
  150. sheet1.groupColumn(9, 12);
  151. sheet1.groupColumn(10, 11);
  152. return "Mixed bag.";
  153. }
  154. }