poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adriana Rozo" <adria...@gmail.com>
Subject Re: Mail attachment
Date Fri, 11 May 2007 17:06:24 GMT
Hi all,

I have the same problem,
this is my code snippet

//HttpServletResponse
getResponse().setContentType("application/vnd.ms-excel");
getResponse().setHeader("Content-disposition","attachment; filename=
"+theNameFile+".xls" );
getResponse().setHeader("Cache-Control"," private");

OutputStream unStream = null;
try {
  unStream = getResponse().getOutputStream();
  workbook.write(unStream); //IT CRASHES
  unStream.flush();
  unStream.close();
 ...

-->> I'm using poi-3.0-alpha1-20050704
But I obtain a NullPointerException

I tryed:

ByteArrayOutputStream byteOutS = new ByteArrayOutputStream();
wb.write(byteOutS);//IT CRASHES
byte[] excelBytes=byteOutS.toByteArray();

And once again NullPointerException

does it work only with FileOutputStream?

thanks
--
Adriana
p.d. sorry for my english... (ó_ò)

On 10/17/06, Brett Procek <b.procek@yahoo.com> wrote:
>
> 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/
>
>


-- 
Adriana
--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.--.
Your grace has found me just as I am,
empty handed but alive in Your hands

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message