Generating Excel Reports using Apache POI in cuba

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?
 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))) {

            }catch(Exception e){


public class ExcelImport extends Screen {
    protected void onButtonExportExcel(Button.ClickEvent event) {

Hi Renuka,

this worked for me:

  • The service returns PDF file as a byte array

  • In the screen, to view the generated PDF.

Hope this helps!


1 Like

Hi Alunetti,

My file name is Test.xlsx and I have specified the file storage location in as shown below.

cuba.fileStorageDir = /export/file

But it is not creating the file in the path specified in
Could you please tell me whether we need to manually create the directories or will cuba create the directories?
Even when i tried creating the directories, the file is not getting created in the path. It is actually getting created at deploy/tomcat/bin folder. What could be the reason for this?

This is because you create it directly using FileOutputStream. CUBA mechanisms are not involved here.