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.hssf.util.HSSFColor;
22:
23: import java.io.FileOutputStream;
24: import java.io.IOException;
25:
26: /**
27: * Demonstrates how to create borders around cells.
28: *
29: * @author Glen Stampoultzis (glens at apache.org)
30: */
31: public class Borders {
32: public static void main(String[] args) throws IOException {
33: HSSFWorkbook wb = new HSSFWorkbook();
34: HSSFSheet sheet = wb.createSheet("new sheet");
35:
36: // Create a row and put some cells in it. Rows are 0 based.
37: HSSFRow row = sheet.createRow((short) 1);
38:
39: // Create a cell and put a value in it.
40: HSSFCell cell = row.createCell((short) 1);
41: cell.setCellValue(4);
42:
43: // Style the cell with borders all around.
44: HSSFCellStyle style = wb.createCellStyle();
45: style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
46: style.setBottomBorderColor(HSSFColor.BLACK.index);
47: style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
48: style.setLeftBorderColor(HSSFColor.GREEN.index);
49: style.setBorderRight(HSSFCellStyle.BORDER_THIN);
50: style.setRightBorderColor(HSSFColor.BLUE.index);
51: style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
52: style.setTopBorderColor(HSSFColor.ORANGE.index);
53: cell.setCellStyle(style);
54:
55: // Write the output to a file
56: FileOutputStream fileOut = new FileOutputStream("workbook.xls");
57: wb.write(fileOut);
58: fileOut.close();
59: }
60: }
|