I have a xlsx file which has multiple sheet i am using apache poi for writing excel, in sheet2 i have 2 columns each column i want to populate by running a for loop , but i see that only last for loop get written previous one get blank in final written output file, i want to write both column by these for loop please help .
for(int i=0;i<fileNamesArray.length;i++)
{
XSSFRow row = worksheet1.createRow(i+1);
cell = row.createCell(0);
cell.setCellValue(fileNamesArray[i].toString());
}//this dont get written
for(int i=0;i<fileDatesArray.length;i++)
{
XSSFRow row = worksheet1.createRow(i+1);
cell = row.createCell(1);
cell.setCellValue(fileDatesArray[i].toString());
}//only this get written
this is complete code
public class DashBoard {
public void writeDashBoard() throws IOException, SQLException
{
CODToolUtil codToolUtil = new CODToolUtil();
// Read property file to initialize constants
String templateDashBoardFile = codToolUtil.getPropValues("templateDashBoardFile");
String outputDir = codToolUtil.getPropValues("outputDir");
String dirSeprator = codToolUtil.getPropValues("dirSeprator");
String fdate = CODToolUtil.getDate();
CODDAO coddao=new CODDAO();
LinkedHashSet<String> hs= new LinkedHashSet<String>();
LinkedHashSet<String> hs1= new LinkedHashSet<String>();
FileInputStream fsIP= new FileInputStream(new File(templateDashBoardFile)); //Template file
XSSFWorkbook wb = new XSSFWorkbook(fsIP);
XSSFSheet worksheet = wb.getSheetAt(0);
Cell cell = null;
cell = worksheet.getRow(1).getCell(0);
cell.setCellValue(CODToolUtil.getDate());//Date
cell = worksheet.getRow(1).getCell(1);
int allfiles=coddao.getAllfiles();
cell.setCellValue(allfiles);//All Files
cell = worksheet.getRow(1).getCell(2);
int callfilesY=coddao.getAllProcessedfilesCallY();
cell.setCellValue(callfilesY);//All Y Files
cell = worksheet.getRow(1).getCell(3);
int callfilesN=coddao.getAllProcessedfilesCallN();
cell.setCellValue(callfilesN);//All N Files
cell = worksheet.getRow(1).getCell(4);
int allLTE=coddao.getAllProcessedfilesLTE();
cell.setCellValue(allLTE);//All LTE Files
cell = worksheet.getRow(1).getCell(5);
int allWCDMA=coddao.getAllProcessedfilesWCDMA();
cell.setCellValue(allWCDMA);//All WCDMA Files
//Sheet 0 OverView Complete
//Sheet 1 Successfull CT
XSSFSheet worksheet1 = wb.getSheetAt(1);
hs=coddao.getAllProcessedfilesNameY();
hs1=coddao.getAllProcessedfilesDateY();
Object[] fileNamesArray = hs.toArray();
Object[] fileDatesArray = hs1.toArray();
for(int i=0;i<fileNamesArray.length;i++)
{
XSSFRow row = worksheet1.createRow(i+1);
cell = row.createCell(0);
cell.setCellValue(fileNamesArray[i].toString());
}//this dont get written
for(int i=0;i<fileDatesArray.length;i++)
{
XSSFRow row = worksheet1.createRow(i+1);
cell = row.createCell(1);
cell.setCellValue(fileDatesArray[i].toString());
}//only this get written
fsIP.close();
File saveDirectory = new File(outputDir);// Create OutPutDirectory
saveDirectory.mkdir();
String savefilePath = saveDirectory.getAbsolutePath();
FileOutputStream output_file = newFileOutputStream(newFile(savefilePath+dirSeprator+fdate+"-"+templateDashBoardFile)); // save in output
wb.write(output_file); // write changes save it.
output_file.close(); // close the stream
}
public static void main(String[] args) throws IOException, SQLException {
new DashBoard().writeDashBoard();
}
}