1 2 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 ; 27 import java.io.IOException ; 28 29 34 public class Outlines 35 { 36 private Outlines(){} 37 38 public static void main(String [] args) 39 throws IOException 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 filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 86 wb.write(fileOut); 87 fileOut.close(); 88 } 89 90 private static void createCase2( String filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 99 wb.write(fileOut); 100 fileOut.close(); 101 } 102 103 private static void createCase3( String filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 113 wb.write(fileOut); 114 fileOut.close(); 115 } 116 117 private static void createCase4( String filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 129 wb.write(fileOut); 130 fileOut.close(); 131 } 132 133 private static void createCase5( String filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 146 wb.write(fileOut); 147 fileOut.close(); 148 } 149 150 private static void createCase6( String filename ) throws IOException { 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 fileOut = new FileOutputStream (filename); 162 wb.write(fileOut); 163 fileOut.close(); 164 } 165 166 private static void createCase7( String filename ) 167 throws IOException 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 fileOut = new FileOutputStream (filename); 176 wb.write(fileOut); 177 fileOut.close(); 178 } 179 180 private static void createCase8( String filename ) 181 throws IOException 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 fileOut = new FileOutputStream (filename); 191 wb.write(fileOut); 192 fileOut.close(); 193 } 194 195 private static void createCase9( String filename ) 196 throws IOException 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 fileOut = new FileOutputStream (filename); 207 wb.write(fileOut); 208 fileOut.close(); 209 } 210 211 212 private static void createCase10( String filename ) 213 throws IOException 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 fileOut = new FileOutputStream (filename); 225 wb.write(fileOut); 226 fileOut.close(); 227 } 228 229 private static void createCase11( String filename ) 230 throws IOException 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 fileOut = new FileOutputStream (filename); 243 wb.write(fileOut); 244 fileOut.close(); 245 } 246 247 private static void createCase12( String filename ) 248 throws IOException 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 fileOut = new FileOutputStream (filename); 260 wb.write(fileOut); 261 fileOut.close(); 262 } 263 264 private static void createCase13( String filename ) 265 throws IOException 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 fileOut = new FileOutputStream (filename); 279 wb.write(fileOut); 280 fileOut.close(); 281 } 282 283 284 } 285 | Popular Tags |