I am using apache poi to create a simple xlsx file using java as follows
String date = "2014/12/29";
XSSFWorkbook w = ADPFidessa.createExcelWorkbook(date);
response.reset();
response.setContentType("application/xlsx");
response.setHeader("Content-Disposition", "attachment;filename=ADP_Fidessa.xlsx");
w.write(response.getOutputStream());
and here is the createExcelWorkbook method
public static XSSFWorkbook createExcelWorkbook(String sBsnsDt) throws Exception
{
// create a new file
FileOutputStream out = new FileOutputStream("workbook.xlsx");
// create a new workbook
XSSFWorkbook wb = new XSSFWorkbook();
// create a new sheet
XSSFSheet s = wb.createSheet("Sheet1");
// declare a row object reference
XSSFRow r;
// declare a cell object reference
XSSFCell c;
ArrayList<ADPFidessa> aDADPFidessalist=null;
ADPFidessaDAO adpfiddao = new ADPFidessaDAO();
aDADPFidessalist=adpfiddao.showADPFid(sBsnsDt);
int rownum;
// header row and columns
r = s.createRow(0);
c = r.createCell(0);
c.setCellValue("Business Date");
c = r.createCell(1);
c.setCellValue("ID");
c = r.createCell(2);
c.setCellValue("Ant");
c = r.createCell(3);
c.setCellValue("Sol");
c = r.createCell(4);
c.setCellValue("itions");
c = r.createCell(5);
c.setCellValue(sition");
c = r.createCell(6);
c.setCellValue("ffere");
c = r.createCell(7);
c.setCellValue("Age");
rownum = 1;
for (ADPFidessa di : aDADPFidessalist)
{
r = s.createRow(rownum);
c = r.createCell(0);
c.setCellValue(di.getBusinessDate());
c = r.createCell(1);
c.setCellValue(di.getkId());
c = r.createCell(2);
c.setCellValue(di.getAnt());
c = r.createCell(3);
c.setCellValue(di.getSol());
c = r.createCell(4);
c.setCellValue(di.getition());
c = r.createCell(5);
c.setCellValue(di.getsition());
c = r.createCell(6);
c.setCellValue(di.getffere());
c = r.createCell(7);
c.setCellValue(di.getAge());
rownum++;
}
try {
wb.write(out);
out.close();
} catch (Exception e) {
System.out.println("Error");
System.out.println(e);
}
return wb;
}
the method showADPFid(sBsnsDt); returns the correct values and the output file is correctly saved. Here is the problem. When i try to open the file in MS Excel, it shows an error message
now, after clicking 'Yes', the excel file opens and all the data is there as expected. However, another dialogue box appears
the log file shows
can anyone please give any idea about this error ? How to resolve this ?
thanks
EDIT: also, here are my imports
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.util.*;