/    Sign up×
Community /Pin to ProfileBookmark

How to email an Apache POI workbook?

I am able to manipulate a spreadsheet using Apache POI, I need to email the spreadsheet to certain recipients.

How do I email an HSSFWorkbook java object?

To send an email without the spreadsheet I am doing the following:
try {
String[] cmdarray = new String[4];
String emailBody = msg;

cmdarray[0] = “mail”;
cmdarray[1] = “-s”;
cmdarray[2] = subject;
cmdarray[3] = toList;

Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmdarray);
BufferedOutputStream out = new BufferedOutputStream(p.getOutputStream());
out.write(emailBody.getBytes());
out.write(“nn”.getBytes()); //Closes the email editor and sends the mail.
out.close();

} catch(Throwable th) {
th.printStackTrace();
}

Please advise, thanks.

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@gecastillauthorDec 05.2008 — The POI project consists of APIs for manipulating various file formats based upon Microsoft's OLE 2 Compound Document format, and Office OpenXML format, using pure Java. In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. POI is your Java Excel solution (for Excel 97-2007). However, we have a complete API for porting other OLE 2 Compound Document formats and welcome others to participate.

http://poi.apache.org/
Copy linkTweet thisAlerts:
@gecastillauthorDec 10.2008 — I figured it out. Look in the JavaMail attachments link is useful http://java.sun.com/developer/online...ingAttachments
×

Success!

Help @gecastill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...