从Java到Excel空单元格

我正在尝试使用Excel创build基于数组的程序。 我已经看了很多教程,我正在用下面的代码尝试它,但正如你可以看到,Java只写在每一行的最后一列。 我希望你可以帮助我

for (int i=0; i<10; i++){ Row row = sheetOLD.createRow(i); Cell cell = row.createCell(0); cell.setCellValue(i); } for (int i=0; i<3; i++){ @SuppressWarnings("resource") Scanner input = new Scanner(System.in); Cell name = sheetOLD.createRow(i).createCell(1); name.setCellValue(input.nextLine()); } Cell test = sheetOLD.createRow(7).createCell(1); test.setCellValue("TEST"); 

在excel中的结果

2和3次使用getRow代替createRow(因为createRowreplace所有行并删除行中的所有单元格):

 for (int i=0; i<10; i++) { Row row = sheetOLD.createRow(i); Cell cell = row.createCell(0); cell.setCellValue(i); } for (int i=0; i<3; i++){ @SuppressWarnings("resource") Scanner input = new Scanner(System.in); Cell name = sheetOLD.getRow(i).createCell(1); name.setCellValue(input.nextLine()); } Cell test = sheetOLD.getRow(7).createCell(1); test.setCellValue("TEST"); 

更多信息,你可以find这个