5

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

4
  • You should at least mention what project you are using in your code sample, best put it in tags too. Commented Aug 22, 2011 at 14:47
  • @Marian, what do you mean with 'project' i am using? Commented Aug 22, 2011 at 17:54
  • well, where does the Workbook class come from? Commented Aug 22, 2011 at 18:22
  • of course, that information is missing. i work with jxl, an excel java api. (added to the tags) jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/… Commented Aug 23, 2011 at 6:45

2 Answers 2

4

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().

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.