how to extract org.dhatim.fastexcel.Workbook into a byte array

89 Views Asked by At

Using Spring boot to generate a org.dhatim.fastexcel.Workbook that contains multiple org.dhatim.fastexcel.Worksheet. Once I have generated the Workbook, I need to extract it as a InputStreamSource to that I can add it to my MimeMessageHelper as an attachment.

I am trying this:

private InputStreamSource getExcelContentAsByteArray(Workbook finalReport) throws IOException {
        // Create a ReadableWorkbook from the input Workbook
        finalReport.finish();
        try (InputStream inputStream = finalReport.toInputStream()) {
            ReadableWorkbook readableWorkbook = new ReadableWorkbook(inputStream);
    
            // Wrap the ReadableWorkbook as an InputStreamSource
            return new InputStreamSource() {
                @Override
                public InputStream getInputStream() throws IOException {
                    return readableWorkbook.read();
                }
            };
        }
}

But obviously its wrong because finalReport.toInputStream() doesn't exist. Is there someway to do this? I really need to send these Workbooks via email.

0

There are 0 best solutions below