我正在尝试使用 Scala 和 Apache POI 读取 Excel 文件。此代码有效,但此后停止。运行时,它会以退出代码 0 正确完成。我正在尝试读取 Excel 文件并打印出存储在其中的名称和地址。我不确定为什么代码不再运行,有人可以帮忙吗?请参阅下文,并在此先感谢您的帮助。
var targetCell= ""
var nameCol: Int = 0
var addressCol: Int = 1
def main(args: Array[String]){
val fileName = "Path to my file"
val file = new FileInputStream(fileName)
val wb = new XSSFWorkbook(file)
val sheet = wb.getSheetAt(0)
for(row <- sheet){
for(cell <- row){
if(cell.getCellType == Cell.Cell_Type_STRING){
cell.getRichStringCellValue.getString.trim == targetCell){
var response= row.getRowNum
val nameCell: XSSFRow = sheet.getRow(response)
val cell:XSSFCell = nameCell.getCell(nameCol)
val addressCell: XSSFCell = tcCell.getCell(addressCol)
println(cell + " " + addressCell)
}
}
}
}
}