Skip to content

Files and byte arrays

firegloves edited this page Jul 20, 2022 · 1 revision

File VS byte array

You can choose to write directly to a file or to obtain the byte array of the generated report (for example to pass it back to a waiting client)

File

Simply pass a file to the MempoiBuilder and the report will be written on file. To get the absolute file path where the report has been saved you can access MempoiReport's file property.

File fileDest = new File("test_with_file.xlsx");

MemPOI memPOI = MempoiBuilder.aMemPOI()
                    .withFile(fileDest)
                    .addMempoiSheet(new MempoiSheet(prepStmt))
                    .build();

CompletableFuture<MempoiReport> fut = memPOI.prepareMempoiReport();
MempoiReport mempoiReport = fut.get();
mempoiReport.getFile(); // will return the string absolute path of the generated report file

Byte array

If you omit to specify a file in the MempoiBuilder, MemPOI will write the report on a byte array. Then you can read the byte array by accessing the MempoiReport's bytes property.

MemPOI memPOI = MempoiBuilder.aMemPOI()
                    .addMempoiSheet (new MempoiSheet(prepStmt))
                    .build();

CompletableFuture<MempoiReport> fut = memPOI.prepareMempoiReport();
MempoiReport mempoiReport = fut.get();
mempoiReport.getBytes(); // will return the byte[] containing the generated report