0
我有一个行迭代器,它经历了Excel表单并获取了该行中的每个单元格值。我已经成功地将值逐行打印出来,但是现在我想将每个单元格存储在单独的变量中,以便我们可以将它们传递到应用程序模块,在那里它们将用作插入函数中的参数。如何在变量中存储单元格值?谢谢。这里是代码:在ADF中获取单元格数据到变量中
try {
InputStream is = file.getInputStream();
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
System.out.print("File is up and the size is " + file.getLength() + " bytes\n");
Iterator<Row> rowIterator = sheet.iterator();
if (rowIterator.hasNext())
rowIterator.next();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t");
// System.out.print(cell.getNumericCellValue()+ "\t");
break;
}
}
System.out.println("");
}
// workbook.close();
// file.close();
}
catch (IOException e) {
System.out.print("greška");
}