Cuba ExportDisplay and Apache POI

Hi CUBA team,

I can see from my last topic: Customize excel exporting that we are able to use Apache POI directly with ExportDisplay.
So I am asking for a demo which shows us how it works.

BTW, I would like to take a look at the example of ExcelExporter that Roman Pinyazhin has been missed in his very first comment of my post.
I will be very thankful if someone could help!

Thank you!

Hello,

simple example of using export display with POI:

@Inject
private ExportDisplay exportDisplay;

@Subscribe
public void onInit(InitEvent event) {
    Workbook wb = new HSSFWorkbook();

    // do something

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        wb.write(out);
    } catch (IOException e) {
        throw new RuntimeException("Unable to write document", e);
    }
    exportDisplay.show(new ByteArrayDataProvider(out.toByteArray()), "test.xls", ExportFormat.XLS);
}

Also, take a look at ExcelExporter class.

1 Like

Thank you @Pinyazhin!