我怎么能转换POI HSSFWorkbook为字节?
调用简单的toBytes()$c$c>不产生字节,但EXEL抛出警告。
Calling Simple toBytes()
does produce the bytes but exel throws Warning.
丢失的文档的信息
周围的Googling给了我这个link看着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 .
作为该邮件列表发帖称
中调用HSSFWorkbook.getBytes()$c$c>不返回所有必要重新数据
构建一个完整的Excel文件。
Invoking
HSSFWorkbook.getBytes()
does not return all of the data necessary to re- construct a complete Excel file.
您可以使用一个ByteArrayOutputStream$c$c>得到的字节数组。
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.)