01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.hssf.usermodel.examples;
19:
20: import org.apache.poi.hssf.usermodel.*;
21: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
22:
23: import java.io.IOException;
24: import java.io.FileOutputStream;
25: import java.io.FileInputStream;
26:
27: /**
28: * @author Glen Stampoultzis (glens at apache.org)
29: */
30: public class RepeatingRowsAndColumns {
31: public static void main(String[] args) throws IOException {
32: HSSFWorkbook wb = new HSSFWorkbook();
33: HSSFSheet sheet1 = wb.createSheet("first sheet");
34: HSSFSheet sheet2 = wb.createSheet("second sheet");
35: HSSFSheet sheet3 = wb.createSheet("third sheet");
36:
37: // POIFSFileSystem fs =
38: // new POIFSFileSystem(new FileInputStream("workbook.xls"));
39: // HSSFWorkbook wb = new HSSFWorkbook(fs);
40: // HSSFSheet sheet1 = wb.getSheetAt(0);
41:
42: HSSFFont boldFont = wb.createFont();
43: boldFont.setFontHeightInPoints((short) 22);
44: boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
45:
46: HSSFCellStyle boldStyle = wb.createCellStyle();
47: boldStyle.setFont(boldFont);
48:
49: HSSFRow row = sheet1.createRow((short) 1);
50: HSSFCell cell = row.createCell((short) 0);
51: cell.setCellValue("This quick brown fox");
52: cell.setCellStyle(boldStyle);
53:
54: // Set the columns to repeat from column 0 to 2 on the first sheet
55: wb.setRepeatingRowsAndColumns(0, 0, 2, -1, -1);
56: // Set the rows to repeat from row 0 to 2 on the second sheet.
57: wb.setRepeatingRowsAndColumns(1, -1, -1, 0, 2);
58: // Set the the repeating rows and columns on the third sheet.
59: wb.setRepeatingRowsAndColumns(2, 4, 5, 1, 2);
60:
61: FileOutputStream fileOut = new FileOutputStream("workbook.xls");
62: wb.write(fileOut);
63: fileOut.close();
64: }
65: }
|