对于HSSFSheet类型,未定义getCell(int)方法

时间:2014-12-18 20:45:39

标签: java excel apache-poi

我正在尝试构建一个二维数组,该数组包含数据表中的值,然后获取这些值并在网站应用程序表单中显示它们。我一直在

  

对于HSSFSheet类型

,未定义getCell(int)方法

错误,我不确定原因。

public static void main(String[] args) throws Exception {
    File file = new File(
            "C:\\Users\\865\\Desktop\\ETAF Selenium\\etaf-selenium-installer\\bin\\Drivers\\64-bit\\IEDriverServer.exe");

    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    File picassoinput = new File("C:\\Users\\865\\Desktop\\ETAF Selenium\\Data Sheets\\PicassoInputData.xls");
    FileInputStream picassofis = new FileInputStream(picassoinput);
    HSSFWorkbook picassowb = new HSSFWorkbook(picassofis);
    HSSFSheet picassows = picassowb.getSheet("Data");

    int rowNum = picassows.getLastRowNum() + 1;
    int colNum = picassows.getRow(0).getLastCellNum();
    String[][] datainput = new String[rowNum][colNum];

    for (int i = 0; i < rowNum; i++) {
        HSSFRow row = picassows.getRow(i);

        for (int j = 0; j < colNum; j++) {
            // the below row of code "HSSFCell cell picassows.getCell(j); is where the error is
            // at

            HSSFCell cell = picassows.getCell(j);

            String value = cellToString(cell);
            datainput[i][j] = value;
        }

    }

    Test2 a = new Test2();

    a.setUp();

    a.testCase();
}

1 个答案:

答案 0 :(得分:2)

以下是您的代码中唯一相关的部分:

HSSFSheet picassows = picassowb.getSheet("Data");
...
HSSFCell cell = picassows.getCell(j);

错误说明:HSSFSheet没有HSSFCell s!

你可能想要:

HSSFCell cell = row.getCell(j);