The PoiReadExcelFile class will read in the 'poi-test.xls' file into an HSSFWorkbook object

风流意气都作罢 提交于 2019-12-25 02:51:31

问题


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();
    }
}
 }

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

What's the problem?


回答1:


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



来源:https://stackoverflow.com/questions/15703988/the-poireadexcelfile-class-will-read-in-the-poi-test-xls-file-into-an-hssfwork

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!