Java:byte[]数组到Excel到BLOB
我有一个 byte[] 数组,需要转换为有效的 Excel 电子表格。转换字节数组后,Excel 电子表格必须缓存到数据库中,最好以 BLOB 形式缓存。
首先,我尝试创建一个 WritableWorkbook:
WritableWorkbook workbook = Workbook.createWorkbook(byteArrayOutputStream);
...
workbook.write();
这对我来说效果很好,但我不知道如何将工作簿作为 BLOB 存储到数据库中。有可能吗?或者还有别的办法吗?
可选:我还可以使用反序列化对象来代替 byte[] 数组。
工作簿 API: http://jexcelapi.sourceforge.net/resources/ javadocs/2_6_10/docs/jxl/Workbook.html
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jdbc 方法
PreparedStatement#setBlob()
采用InputStream
作为数据源参数。只需在 byteArrayOutputStream 的缓冲区上创建一个ByteArrayInputStream
并将其传递给setBlob()
即可。The jdbc method
PreparedStatement#setBlob()
takes anInputStream
as the data source argument. Just create aByteArrayInputStream
over the buffer of your byteArrayOutputStream and pass that tosetBlob()
.jxl 中没有方法可以从 writableWorkSheet 获取输出流或字节数组。
There is no method in jxl from where we can get outputstream or the byte array from the writableWorkSheet.