【发布时间】:2015-05-08 13:47:12
【问题描述】:
我正在尝试在 Excel 中使用电子表格中的数据,但总是出现此错误,已尝试将工作表格式化为文本和数字,但错误仍然存在。
我看到有人使用它解决了cell.setCellType ( Cell.CELL_TYPE_STRING ) ;,但我不知道我的代码中的这段代码的位置。
WebElement searchbox = driver.findElement(By.name("j_username"));
WebElement searchbox2 = driver.findElement(By.name("j_password"));
try {
FileInputStream file = new FileInputStream(new File("C:\\paulo.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
for (int i=1; i <= sheet.getLastRowNum(); i++){
String j_username = sheet.getRow(i).getCell(0).getStringCellValue();
String j_password = sheet.getRow(i).getCell(0).getStringCellValue();
searchbox.sendKeys(j_username);
searchbox2.sendKeys(j_password);
searchbox.submit();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
}
workbook.close();
file.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
【问题讨论】:
-
你能放置完整的堆栈跟踪错误消息吗?
-
sheet.getRow(i).getCell(0).toString()呢? -
@Abdull 你的评论比官方的回答更重要:) 解决了我的问题
-
如果您需要字符串形式的数字类型,请尝试 cell.getRawValue():stackoverflow.com/questions/13563747
标签: java apache-poi