У меня проблемы с записью данных в таблицу Excel.Моя другая часть программы сгенерирует ArrayList объектов и отправит его в этот цикл.Этот цикл читает один объект за другим и записывает в лист Excel.
Я знаю, что что-то упустил.Он записывает только последний объект из списка.
Если я попытаюсь поместить этот код в цикл while:
FileOutputStream out = new FileOutputStream(writeExcel);
writeExtraBook.write(out);
out.close();
Затем он записывает в файл только первую запись.
Может кто-нибудь помочь мне, где я делаю не так
Вот код, который записывает данные:
String writeExcel = CONSTANTS.FOW_FILE_PATH;
FileInputStream writeInput;
try {
writeInput = new FileInputStream(writeExcel);
/** Create a POIFSFileSystem object **/
POIFSFileSystem mywriteSystem = new POIFSFileSystem(writeInput);
HSSFWorkbook writeExtraBook = new HSSFWorkbook(mywriteSystem);
HSSFSheet myExtrasSheet = writeExtraBook.getSheet("FOW");
HSSFRow extraRow = null;
HSSFCell extraRowCell = null;
int lastRowNumber = myExtrasSheet.getLastRowNum();
Iterator<FoWForm> iter = fowList.iterator();
while (iter.hasNext()) {
extraRow = myExtrasSheet.createRow(lastRowNumber + 1);
FoWForm form = iter.next();
extraRowCell = extraRow.createCell(0);
extraRowCell.setCellValue(lastRowNumber + 1);
extraRowCell = extraRow.createCell(1);
extraRowCell.setCellValue(form.getFowDesc());
extraRowCell = extraRow.createCell(2);
extraRowCell.setCellValue(form.getForCountry());
extraRowCell = extraRow.createCell(3);
extraRowCell.setCellValue(form.getMatchId());
extraRowCell = extraRow.createCell(4);
extraRowCell.setCellValue(form.getAgainstCountry());
}
FileOutputStream out = new FileOutputStream(writeExcel);
writeExtraBook.write(out);
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}