How can I convert POI HSSFWorkbook to bytes?

后端 未结 2 1047
旧巷少年郎
旧巷少年郎 2020-12-13 23:54

Calling Simple toBytes() does produce the bytes but exel throws Warning.

Lost Document information

Googling around gave me this

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 00:50

    How about:

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    byte[] xls = baos.toByteArray();
    

    In order to get a full excel file out, you must call the write(OutputStream) method. If you want bytes from that, just give a ByteArrayOutputStream

提交回复
热议问题