File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Generate Excel file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Generate Excel file" Watch "Generate Excel file" New topic

Generate Excel file

M Yuvi

Joined: Mar 19, 2008
Posts: 9

The requirement is to read the data available in the database and send them as excel stream to another web application - in specific a JSP page.

1. Everytime I read the records from the database, should I generate an Excel sheet and store the excel file physically before sending it across? What is the better way to implement this?

2. Which API is better to use to generate the excel sheet, write the data into it, read the data from it and send it across as excel stream?

3. How do I send the data as excel stream to the other application?

Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
You can use the jxl Java Excel API. Create a writable workbook to an output stream. Then use that output stream to channel the bytes into a post you can send to the receiving URL.

This example shows how to post using Java

In this code:

The file is accessed as a File, but you can get the FilePart to load from a stream by using

And putting a ByteArrayPartSource as the source.

The ByteArrayPartSource in turn gets the byte[] from the output stream you used to store the excel file (ByteArrayOutputStream maybe?)
Don't get me started about those stupid light bulbs.
subject: Generate Excel file
It's not a secret anymore!