本周末我正在教自己Apache POI。我的最新任务是获取具有数值和空白单元格的列,并将值添加到空白列中。我认为我使用switch语句和setCellValues几乎完成了这么多,但我似乎无法将内容输出回特定工作表和列上的工作簿。
以下是我的内容。数据很好地被拉入方法。
Random randomNum = new Random();
double randomD = randomNum .nextDouble();
for (Row row : sheet2) {
for (Cell cell : row) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
System.out.println(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_BLANK:
cell.setCellValue(randomD);
FileOutputStream fileOut = new FileOutputStream("C:/Users/testtest/Desktop/Test/ProductTests.xls");
wb.write(fileOut);
fileOut.close();
System.out.println(cell.getNumericCellValue());
break;
default:
System.out.println();
}
}
}