How can I convert POI HSSFWorkbook to bytes?

As that mailing list post said

Invoking HSSFWorkbook.getBytes() does not return all of the data necessary to re-
construct a complete Excel file.

You can use the write method with a ByteArrayOutputStream to get at the byte array.

ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
    workbook.write(bos);
} finally {
    bos.close();
}
byte[] bytes = bos.toByteArray();

(The close call is not really needed for a ByteArrayOutputStream, but imho it is good style to include anyway in case its later changed to a different kind of stream.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)