Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate Excel file

 
M Yuvi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Thanks
Yuvi
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

http://samindaw.wordpress.com/2008/11/24/how-to-post-or-upload-a-file-to-a-url-or-servelet-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?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic