PoiReadExcelFile 类将在 'poi-test.xls' 文件中读入一个 HSSFWorkbook 对象 [英] The PoiReadExcelFile class will read in the 'poi-test.xls' file into an HSSFWorkbook object

查看:30
本文介绍了PoiReadExcelFile 类将在 'poi-test.xls' 文件中读入一个 HSSFWorkbook 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了这个代码,PoiReadExcelFile 类将把 'poi-test.xls' 文件读入一个 HSSFWorkbook 对象.然后将POI Worksheet"读入 HSSFWorksheet 对象,然后将读取 A1、B1、C1 和 D1 单元格中的值并显示到标准输出.

I've created this code and The PoiReadExcelFile class will read in the 'poi-test.xls' file into an HSSFWorkbook object. The 'POI Worksheet' will then be read into an HSSFWorksheet object, and then the values within the A1, B1, C1, and D1 cells will be read and displayed to standard output.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiReadExcelFile {
public static void main(String[] args) {
    try {
        FileInputStream fileInputStream = new FileInputStream("poi-    

      test.xls");
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
        HSSFSheet worksheet = workbook.getSheet("POI Worksheet");
        HSSFRow row1 = worksheet.getRow(0);
        HSSFCell cellA1 = row1.getCell((short) 0);
        String a1Val = cellA1.getStringCellValue();
        HSSFCell cellB1 = row1.getCell((short) 1);
        String b1Val = cellB1.getStringCellValue();
        HSSFCell cellC1 = row1.getCell((short) 2);
        boolean c1Val = cellC1.getBooleanCellValue();
        HSSFCell cellD1 = row1.getCell((short) 3);
        Date d1Val = cellD1.getDateCellValue();

        System.out.println("A1: " + a1Val);
        System.out.println("B1: " + b1Val);
        System.out.println("C1: " + c1Val);
        System.out.println("D1: " + d1Val);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 }

当我运行这段代码时,我得到了这个:用法:BiffDrawingToXml [options] inputWorkbook选项:-exclude-workbook 排除工作簿级记录-sheet-indexes 输出具有指定索引的工作表-sheet-namek 输出指定名称的工作表

When i ran this code i got this: Usage: BiffDrawingToXml [options] inputWorkbook Options: -exclude-workbook exclude workbook-level records -sheet-indexes output sheets with specified indexes -sheet-namek output sheets with specified name

有什么问题?

推荐答案

请使用右键单击运行选项运行类文件.当唯一的 JAR 文件正在运行时会出现上述消息.

Please run the class file using right click run option. The above message while come when the only JAR file is getting run.

这篇关于PoiReadExcelFile 类将在 'poi-test.xls' 文件中读入一个 HSSFWorkbook 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆