You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Kurt Stein <ku...@liquio.com> on 2005/03/04 15:27:55 UTC

Saving a workbook as an email attachment

Does anyone know how to insert an HSSFWorkbook into a mime attachment?

Is there a best practice for getting the workbook.write(OutputStream
out)output convert to byte[] and other handler structures used with
java.mail functionality?

Thanks

Kurt

Kurt W. Stein
Liquio Corporation
318 W. Adams Street
Suite 1306
Chicago, IL 60606
(312) 750-1111
(312) 750-6775 fax
kurt.stein@liquio.com


---------------------------------------------------------------------
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/


RE: Saving a workbook as an email attachment

Posted by Kurt Stein <ku...@liquio.com>.
Thanks for the link from Sun.
Saving and sending is quite straight forward, redirecting the stream is a
bit harder.

Personally I would say it is related to POI as the output is from poi into
an attachment.
If the HSSFWorkbook write methods had more constructors, writing to email
attachment would be easier.

Pardon my lack of knowledge of the posting rules and regulations of the
POINazi's!

Believe me - I have suffered through some thoroughly inane posts!


KStein

-----Original Message-----
From: Kamal Upadhyay [mailto:kamal.upadhyay@gmail.com]
Sent: Monday, March 14, 2005 2:00 AM
To: POI Users List; kurt.stein@liquio.com
Subject: Re: Saving a workbook as an email attachment


HI, sending mail and POI r two diferent issues all together. U could
do the latter either by saving the generated excel file in the file
system and then reading it using mail api, see the code below...
however i repeat this is not related to POI so do not post it here
rather check this thread
http://forum.java.sun.com/thread.jspa?forumID=43&threadID=581609

// create the message part with attachment
			MimeBodyPart mbp = new MimeBodyPart();
// attach the data to the message
			mbp.setDataHandler(new FileHandler(new FileInputStream(new
File("location of ur file"))l;
// create the Multipart and add its parts to it
			Multipart mp = new MimeMultipart();
			mp.addBodyPart(mbp);
// add the Multipart to the message
			msg.setContent(mp);
			Transport.send(msg);

or better still with zero footprint like this
// attach the data to the message
			MyDataSource mds = new MyDataSource(bos, "APPLICATION/OCTET-STREAM");
			mbp2.setDataHandler(new DataHandler(mds));
			mbp2.setFileName(reportName + ".xls");


On Fri, 4 Mar 2005 08:27:55 -0600, Kurt Stein <ku...@liquio.com> wrote:
> Does anyone know how to insert an HSSFWorkbook into a mime attachment?
>
> Is there a best practice for getting the workbook.write(OutputStream
> out)output convert to byte[] and other handler structures used with
> java.mail functionality?
>
> Thanks
>
> Kurt
>
> Kurt W. Stein
> Liquio Corporation
> 318 W. Adams Street
> Suite 1306
> Chicago, IL 60606
> (312) 750-1111
> (312) 750-6775 fax
> kurt.stein@liquio.com
>
> ---------------------------------------------------------------------
> 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/
>
>


--
bye
kamal
(Verizon, Chennai)
Contact No: 09884339257


On Fri, 4 Mar 2005 08:27:55 -0600, Kurt Stein <ku...@liquio.com> wrote:
> Does anyone know how to insert an HSSFWorkbook into a mime attachment?
>
> Is there a best practice for getting the workbook.write(OutputStream
> out)output convert to byte[] and other handler structures used with
> java.mail functionality?
>
> Thanks
>
> Kurt
>
> Kurt W. Stein
> Liquio Corporation
> 318 W. Adams Street
> Suite 1306
> Chicago, IL 60606
> (312) 750-1111
> (312) 750-6775 fax
> kurt.stein@liquio.com
>
> ---------------------------------------------------------------------
> 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/
>
>


--
bye
kamal
(Verizon, Chennai)
Contact No: 09884339257

---------------------------------------------------------------------
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/



---------------------------------------------------------------------
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/


Re: Saving a workbook as an email attachment

Posted by Kamal Upadhyay <ka...@gmail.com>.
HI, sending mail and POI r two diferent issues all together. U could
do the latter either by saving the generated excel file in the file
system and then reading it using mail api, see the code below...
however i repeat this is not related to POI so do not post it here
rather check this thread
http://forum.java.sun.com/thread.jspa?forumID=43&threadID=581609

// create the message part with attachment 
			MimeBodyPart mbp = new MimeBodyPart(); 
// attach the data to the message
			mbp.setDataHandler(new FileHandler(new FileInputStream(new
File("location of ur file"))l;
// create the Multipart and add its parts to it 
			Multipart mp = new MimeMultipart(); 
			mp.addBodyPart(mbp); 
// add the Multipart to the message 
			msg.setContent(mp);
			Transport.send(msg);

or better still with zero footprint like this 
// attach the data to the message
			MyDataSource mds = new MyDataSource(bos, "APPLICATION/OCTET-STREAM");
			mbp2.setDataHandler(new DataHandler(mds));
			mbp2.setFileName(reportName + ".xls");


On Fri, 4 Mar 2005 08:27:55 -0600, Kurt Stein <ku...@liquio.com> wrote:
> Does anyone know how to insert an HSSFWorkbook into a mime attachment?
> 
> Is there a best practice for getting the workbook.write(OutputStream
> out)output convert to byte[] and other handler structures used with
> java.mail functionality?
> 
> Thanks
> 
> Kurt
> 
> Kurt W. Stein
> Liquio Corporation
> 318 W. Adams Street
> Suite 1306
> Chicago, IL 60606
> (312) 750-1111
> (312) 750-6775 fax
> kurt.stein@liquio.com
> 
> ---------------------------------------------------------------------
> 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/
> 
> 


-- 
bye
kamal
(Verizon, Chennai)
Contact No: 09884339257


On Fri, 4 Mar 2005 08:27:55 -0600, Kurt Stein <ku...@liquio.com> wrote:
> Does anyone know how to insert an HSSFWorkbook into a mime attachment?
> 
> Is there a best practice for getting the workbook.write(OutputStream
> out)output convert to byte[] and other handler structures used with
> java.mail functionality?
> 
> Thanks
> 
> Kurt
> 
> Kurt W. Stein
> Liquio Corporation
> 318 W. Adams Street
> Suite 1306
> Chicago, IL 60606
> (312) 750-1111
> (312) 750-6775 fax
> kurt.stein@liquio.com
> 
> ---------------------------------------------------------------------
> 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/
> 
> 


-- 
bye
kamal
(Verizon, Chennai)
Contact No: 09884339257

---------------------------------------------------------------------
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/