我对Selenium很新,并通过自学来学习。任何帮助都会很明显。
目前我正在使用
String data = wb.getSheetAt(sheetnum).getRow(row).getCell(col).getStringCellValue();
它适用于String但不适用于数字。我的单元格值为'500'
,我想要获取它。请帮忙。
答案 0 :(得分:0)
尝试以下代码:
public void readfile(String filepath, String filename, String sheetname) throws IOException {
File file = new File(filepath+"\\"+filename);
FileInputStream fis = new FileInputStream(file);
// for creating .xlsx workbook
Workbook wb = new XSSFWorkbook(fis);
// for reading the sheet by its name
Sheet sh = wb.getSheet(sheetname);
// find the total rows in sheet
int rowcount = sh.getLastRowNum() - sh.getFirstRowNum();
// create a loop to create
for (int i = 0; i < rowcount + 1; i++) {
Row row = sh.getRow(i);
// create a loop to print cell values
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(row.getCell(j).getStringCellValue() + " ");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print((int)row.getCell(j).getNumericCellValue() + " ");
break;
}
}
System.out.println();
}
}
希望它会对你有所帮助。
答案 1 :(得分:0)
Double data = wb.getSheetAt(sheetnum).getRow(row).getCell(col).getNumericCellValue();