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.HSSFCell;
21: import org.apache.poi.hssf.usermodel.HSSFRow;
22: import org.apache.poi.hssf.usermodel.HSSFSheet;
23: import org.apache.poi.hssf.usermodel.HSSFWorkbook;
24:
25: import java.io.FileOutputStream;
26: import java.io.IOException;
27: import java.util.Date;
28:
29: public class CellTypes {
30: public static void main(String[] args) throws IOException {
31: HSSFWorkbook wb = new HSSFWorkbook();
32: HSSFSheet sheet = wb.createSheet("new sheet");
33: HSSFRow row = sheet.createRow((short) 2);
34: row.createCell((short) 0).setCellValue(1.1);
35: row.createCell((short) 1).setCellValue(new Date());
36: row.createCell((short) 2).setCellValue("a string");
37: row.createCell((short) 3).setCellValue(true);
38: row.createCell((short) 4).setCellType(HSSFCell.CELL_TYPE_ERROR);
39:
40: // Write the output to a file
41: FileOutputStream fileOut = new FileOutputStream("workbook.xls");
42: wb.write(fileOut);
43: fileOut.close();
44: }
45: }
|