I dont know why I cannot write 2 cell value with setCellValue() , it only update only 1 value in x1 cell and x2 cell not. I have a file excel and I want update value for this file with data from arraylist listThoaiThang, tt.getNoiBo() and tt.getNgoaiMang() is a string and not null when log.
Code are below, thank you.
public void writeFile(ArrayList<LLThoaiNoiHat> llList) {
FileInputStream fis = null;
try {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String date1 = dateFormat.format(new Date()).toString();
File tongHop = new File("Thongke_LL_NOIHAT_VTT_" + date1 + ".xlsx");
copyFileUsingApacheCommonsIO(new File("Mau_Thongke_LL_NOIHAT_VTT.xlsx"), tongHop); //copy sample file before edit data
fis = new FileInputStream(tongHop);
BufferedInputStream bis = new BufferedInputStream(fis);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
Sheet sheet = workbook.getSheetAt(0);
fis.close();
int rowNum = 9;
Row row;
ArrayList<LLThoaiThang> listThoaiThang;
for (LLThoaiNoiHat tnh : llList) {
row = sheet.getRow(rowNum++);
int colNum = 2;
listThoaiThang =tnh.getListThoaiThang();
for (LLThoaiThang tt :listThoaiThang ) {
int aa = tt.getThang() / 2+3;
Cell x1 = row.getCell(aa);
x1.setCellValue(tt.getNoiBo()); //only first cell ok
Cell x2 = row.getCell(aa+1);
x2.setCellValue(tt.getNgoaiMang());//this cell cannot change value and all cell after cannot change value
}
}
FileOutputStream outFile = new FileOutputStream(tongHop);
workbook.write(outFile);
outFile.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}