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


  对于类型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();
}

最佳答案

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

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


如错误所示:HSSFSheet没有HSSFCell

您可能想要:

HSSFCell cell = row.getCell(j);

10-03 00:50