poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brett Procek <b.pro...@yahoo.com>
Subject Re: Mail attachment
Date Tue, 17 Oct 2006 21:58:40 GMT
Anil Komareddi <anil <at> effone.net> writes:

> I'm trying to generate an excel spreadsheet and then email it as an
> attachment. The generation part works fine. I can save this to a file
> and view it. I can attach an existing spreadsheet file to an email and
> send it and it goes out ok. The problem is when I try to generate the
> spreadsheet and attach it without saving it first.
> This is what I'm doing:
> 1. Generate the workbook
> 2. Get the data byte array from the workbook using
> HSSFWorkbook.getBytes()
> 3. Prepare a javax.activation.Datasource using this byte array where the
> getInputStream method is as follows:
>     public InputStream getInputStream()
>                                throws IOException
>     {
>         if (_data == null)
>         {
>             throw new IOException("no data");
>         }
>         return new ByteArrayInputStream(_data);
>     }
> 4. The emailer code itself, looks like this:
> "Lost Document Summary Information"

I had this same issue and figured out the problem.  Invoking 
HSSFWorkbook.getBytes() does not return all of the data necessary to re-
construct a complete Excel file. An excel file itself contains more than the 
raw contents of the file.  The 'getBytes()' method apparently seems to miss 
other excell file meta data, including the file summary information, etc.

Instead, in order to write the file out as an attachment, or stream, you must 
invoke the 'write()' method on the workbook itself, passing in a OutputSteam.

- Brett

To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

View raw message