Hi,
I want to generate excel reports using apache poi in cuba. I want the file to be generated at a location i specify in the code and show the file getting downloaded in the browser. Below is my sample code. The file is not getting created. Could you please help?
serviceBean.java
public void ExportExcel(){
final String fileName = "Test.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Test Data");
.....
// Generate the header and content for excel
....
try (FileOutputStream outputStream = new FileOutputStream(new File(fileName))) {
workbook.write(outputStream);
outputStream.flush();
}catch(Exception e){
e.printStackTrace();
}
}
public class ExcelImport extends Screen {
@Subscribe("btnExportExcel")
protected void onButtonExportExcel(Button.ClickEvent event) {
service.ExportExcel();
}
}