0

我已经创建了这段代码,PoiReadExcelFile 类会将“poi-test.xls”文件读入 HSSFWorkbook 对象。然后将“POI 工作表”读入 HSSFWorksheet 对象,然后读取 A1、B1、C1 和 D1 单元格中的值并显示到标准输出。

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 具有指定名称的输出表

有什么问题?

4

1 回答 1

1

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

于 2018-04-05T02:34:02.040 回答