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.HSSFWorkbook;
21: import org.apache.poi.hssf.usermodel.HSSFSheet;
22: import org.apache.poi.hssf.usermodel.HSSFRow;
23: import org.apache.poi.hssf.usermodel.HSSFCell;
24:
25: import java.io.FileOutputStream;
26: import java.io.IOException;
27:
28: /**
29: * Illustrates how to create cell values.
30: *
31: * @author Glen Stampoultzis (glens at apache.org)
32: */
33: public class CreateCells {
34: public static void main(String[] args) throws IOException {
35: HSSFWorkbook wb = new HSSFWorkbook();
36: HSSFSheet sheet = wb.createSheet("new sheet");
37:
38: // Create a row and put some cells in it. Rows are 0 based.
39: HSSFRow row = sheet.createRow((short) 0);
40: // Create a cell and put a value in it.
41: HSSFCell cell = row.createCell((short) 0);
42: cell.setCellValue(1);
43:
44: // Or do it on one line.
45: row.createCell((short) 1).setCellValue(1.2);
46: row.createCell((short) 2).setCellValue("This is a string");
47: row.createCell((short) 3).setCellValue(true);
48:
49: // Write the output to a file
50: FileOutputStream fileOut = new FileOutputStream("workbook.xls");
51: wb.write(fileOut);
52: fileOut.close();
53: }
54: }
|