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:
22: import java.io.FileOutputStream;
23: import java.io.IOException;
24:
25: /**
26: * Demonstrates how to create and use fonts.
27: *
28: * @author Glen Stampoultzis (glens at apache.org)
29: */
30: public class WorkingWithFonts {
31: public static void main(String[] args) throws IOException {
32: HSSFWorkbook wb = new HSSFWorkbook();
33: HSSFSheet sheet = wb.createSheet("new sheet");
34:
35: // Create a row and put some cells in it. Rows are 0 based.
36: HSSFRow row = sheet.createRow((short) 1);
37:
38: // Create a new font and alter it.
39: HSSFFont font = wb.createFont();
40: font.setFontHeightInPoints((short) 24);
41: font.setFontName("Courier New");
42: font.setItalic(true);
43: font.setStrikeout(true);
44:
45: // Fonts are set into a style so create a new one to use.
46: HSSFCellStyle style = wb.createCellStyle();
47: style.setFont(font);
48:
49: // Create a cell and put a value in it.
50: HSSFCell cell = row.createCell((short) 1);
51: cell.setCellValue("This is a test of fonts");
52: cell.setCellStyle(style);
53:
54: // Write the output to a file
55: FileOutputStream fileOut = new FileOutputStream("workbook.xls");
56: wb.write(fileOut);
57: fileOut.close();
58:
59: }
60: }
|