I am posting my method that I am using to write data in excel sheet.
public void createMonthExcelSheet(String stt[]){
try{
String str="";
for(int p=0;p<stt.length;p++){
str+=stt[p];
}
String path=System.getProperty("user.dir");
//String path="D:";
//ByteArrayOutputStream outputStream = new
ByteArrayOutputStream();
//String destinationFilePath = ""+path+"\\Report.xlsx";
log.info("Preparing excel sheet.");
//FileOutputStream fout = new
FileOutputStream(destinationFilePath);
FileOutputStream fout = new
FileOutputStream(path+"\\Report.xlsx");
//HSSFWorkbook workBook=new HSSFWorkbook();
//Workbook workBook = new XSSFWorkbook();
XSSFWorkbook workBook = new XSSFWorkbook();
XSSFSheet spreadSheet=null;
//Sheet spreadSheet=null;
String m[]=str.split("::");
for(int i=1;i<stt.length;i++){
//int rem=i%3;
//int div=i/3;
String success="Sucess";
String failed="Failed";
String Main_Sheet="";
if((i%2)==0){
Main_Sheet=success;
}
else{
Main_Sheet=failed;
}
spreadSheet = workBook.createSheet(Main_Sheet);
int maxRow=SpreadsheetVersion.EXCEL2007.getLastRowIndex();
System.out.println("no of row : "+maxRow);
//Row row=spreadSheet.createRow((short)0);
XSSFRow row=spreadSheet.createRow((short)0);
//Cell cell;
row.createCell(0).setCellValue("Call Date");
row.createCell(1).setCellValue("Start Time");
row.createCell(2).setCellValue("End Time");
row.createCell(3).setCellValue("Account");
row.createCell(4).setCellValue("Mobile");
row.createCell(5).setCellValue("Duration");
row.createCell(6).setCellValue("Call Status");
row.createCell(7).setCellValue("Pulse");
/*cell = row.createCell(0);
cell.setCellValue("Call Date");
cell = row.createCell(1);
cell.setCellValue("Start Time");
cell=row.createCell(2);
cell.setCellValue("End Time");
cell=row.createCell(3);
cell.setCellValue("Account");
cell=row.createCell(4);
cell.setCellValue("Mobile");
cell=row.createCell(5);
cell.setCellValue("Duration");
cell=row.createCell(6);
cell.setCellValue("Call Status");
cell=row.createCell(7);
cell.setCellValue("Pulse");
*/
String s[]=stt[i].split(";;");
int n=0;
for(int j=0;j<s.length;j++){
n++;
//Row row2 = spreadSheet.createRow((short)n);
XSSFRow row2 = spreadSheet.createRow((short)n);
String t[]=s[j].split("%%");
for(int k=0;k<t.length;k++){
row2.createCell(k).setCellValue(t[k]);
//spreadSheet.createRow((short)n).createCell(k).setCellValue(t[k]);
}
}
}
workBook.write(fout);
//workBook.write(outputStream);
//outputStream.writeTo(fout);
//outputStream.close();
fout.close();
log.info("Excel sheet has prepared.");
}
catch(Exception e){
log.error("Error : "+e.getMessage());
e.printStackTrace();
}
}
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Exception-tp5715558.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]