我怎么能转换POI HSSFWorkbook为字节? [英] How can I convert POI HSSFWorkbook to bytes?

查看:1578
本文介绍了我怎么能转换POI HSSFWorkbook为字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用简单的<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#getBytes%28%29\"><$c$c>toBytes()不产生字节,但EXEL抛出警告。

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

丢失的文档的信息

周围的Googling给了我这个<一个href=\"http://mail-archives.apache.org/mod_mbox/poi-user/200610.mbox/%3Cloom.20061017T235349-739@post.gmane.org%3E\">link看着<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#getBytes%28%29\">Javadocs对于工作表和POI HOW-TO 的说,类似的事情。基本上,我不能让字节而不会丢失一些信息,并使用方法来代替。

Googling around gave me this link and looking at Javadocs for worksheet and POI HOW-TO say similar things . Basically I can not get Bytes without loosing some information and should use the write method instead.

虽然写做做工精细我真的需要送过来的字节数。有没有什么办法可以做到这一点?这就是获得字节与出得到任何警告。

While write does work fine I really need to send the bytes over . Is there any way I can do that ? That is get the bytes with out getting any warning .

推荐答案

作为该邮件列表发帖称

中调用<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#getBytes%28%29\"><$c$c>HSSFWorkbook.getBytes()不返回所有必要重新数据
  构建一个完整的Excel文件。

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

您可以使用一个<一个write方法href=\"http://docs.oracle.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html\"><$c$c>ByteArrayOutputStream得到的字节数组。

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

(即关闭电话是不是真的需要为 ByteArrayOutputStream ,但恕我直言,这是很好的风格反正包括在情况下,它后来改为别样流。)

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

这篇关于我怎么能转换POI HSSFWorkbook为字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆