I am using Apache Poi to create an Excel file for my project, but I met a few weird issues while trying it.
public void createfile(Request request, Response response) throws Exception {
try {
Integer id = ParamUtils.getParamInt(request, "id", null);
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("new sheet");
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
workbook.write(fileOut);
fileOut.close();
}
catch (IncorrectData e) {
return e;
}
}
Firstly, I got a format or extension that is not valid error when I try to open the file I create with this function. Secondly, I got file in use locked for editing by another user but I clearly closed OutputStream at the end of the code. One last question, it was a function at my server and I was wondering if I can pass/return this Excel file to the front to download it?
Thanks!