0xPixelfrost
0xPixelfrost

Reputation: 10454

Java: byte[] Array to Excel to BLOB

i have an byte[] array that needs to be converted into an valid excel spreadsheet. After converting the byte array, the excel spreadsheet must be cached into the database preferably as BLOB.

First I tried to create an WritableWorkbook with:

WritableWorkbook workbook = Workbook.createWorkbook(byteArrayOutputStream);
...
workbook.write();

This would work fine for me, but i have no idea how to store a workbook as BLOB into the database. Is it even possible? Or is there another way?

Optionally: Instead of the byte[] array I also could use a deserialized object.

Workbook API: http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/Workbook.html

Upvotes: 5

Views: 8802

Answers (2)

Vishesh
Vishesh

Reputation: 111

There is no method in jxl from where we can get outputstream or the byte array from the writableWorkSheet.

Upvotes: 1

Jim Garrison
Jim Garrison

Reputation: 86774

The jdbc method PreparedStatement#setBlob() takes an InputStream as the data source argument. Just create a ByteArrayInputStream over the buffer of your byteArrayOutputStream and pass that to setBlob().

Upvotes: 4

Related Questions