Bir excel sayfasına veri yazmakta sorun yaşıyorum. Programın diğer kısımları bir ArrayList of Objects oluşturacak ve bu döngüye gönderecektir. Bu döngü bir nesneyi diğerinden sonra okur ve Excel sayfasına yazar.Ya da listenin ilk Kaydı veya Son Kaydı yazıyor, doğru olan tüm öneriler
Bir şeyleri kaçırdığımı biliyorum. Listeden sadece son nesneyi yazar.
ben döngü içindeyken bu kodu yerleştirmeye çalışırsanız:
FileOutputStream out = new FileOutputStream(writeExcel);
writeExtraBook.write(out);
out.close();
Sonra dosyaya sadece ilk kayıt yazar. Sen
int lastRowNumber = myExtrasSheet.getLastRowNum();
...
while (iter.hasNext()) {
extraRow = myExtrasSheet.createRow(lastRowNumber + 1);
:
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();
}
Süper İşe yaradı !!!! – gmhk
@harigm: Peki neden postayı sildin? (Şimdi kurtarılmamış ...) Cevabını başkalarına yardım edebilecek bir soru sorduğunda, onu neden silmek istediğini anlamıyorum ... –
Bir kez cevaplanamayan bir soru silinemedi. bu yeni mi? – Baz1nga