File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Creating Multiple worsheets in Excel document using servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating Multiple worsheets in Excel document using servlets" Watch "Creating Multiple worsheets in Excel document using servlets" New topic
Author

Creating Multiple worsheets in Excel document using servlets

bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
Hi,

I tried to output my html tables into the excel sheet just by setting the response.setContentType method and got succeeded without using any APIs like POI or JXL. Now, can anyone help me to create a multiple workshhets in the same excel file without any APIs and just by using the servelt's setContentType method only..

Regards,
Bhaskar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
I'm 99% sure that this can't be done, because Excel does not support this.


Ping & DNS - my free Android networking tools app
bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
Ulf Dittmer wrote:I'm 99% sure that this can't be done, because Excel does not support this.


Hi Dittmer,

Which one is not possible? Creating the Excel file or creating multiple sheets in a single excel file??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42262
    
  64
It is easily possible to create an Excel file containing multiple sheets using a library like Apache POI. What I don't think is possible is to create HTML tables, and somehow have Excel import that into a document containing multiple sheets (which is what you asked).

My name is Ulf, by the way. If you prefer to call me by my last name, then the polite way to do so is to call me "Mr. Dittmer". First name is fine, though.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2393
    
  28

What did you set as your content type? and when you say HTML table, you mean it has <table> <td><tr> tags?
bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
I set the content-type as "application/vnd.ms-excel". I am trying to write the html tables (<table> <td><tr> tags) in the excel file as below:

where = "sample.xls";
File f = new File(where);
Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
w.write("<table border=1>\r\n");

This will create a single worksheet.


Regards,
Bhaskar
Rajesh Ronald Reagan
Greenhorn

Joined: May 28, 2013
Posts: 7
Hello Bhaskar,

I believe you have set the response object's content type to the following.



It means the response object writes this data to ms-excel format.

Serlvet API can only set the content type to microsoft excel format. There is no API for creating for multiple workbook.

If you have verified the generated xls file, you could have noticed only one worksheet possibly without the grey lines. Servlet API supports only the content type to microsoft excel, but not the Excel creation API.

If you have table data or results put it into an arraylist , initialize the jxl write class to write it to multiple worksheet.

Till now Oracle Corp, has not found Servlet API to create excel worksheets.

Regards,
Ronald Reagan Jr
bhaskar selvaraj
Greenhorn

Joined: Nov 05, 2012
Posts: 9
Hello Ronald,

Thanks for your clarification. Now i am clear that we can generate only one work sheet in the excel using servlets. In order to create multiple worksheet we need to use Java Excel APIs like JXL or APache POI.



Regards,
Bhaskar
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
Using text-based templates to generate multi-part sheets in XML format works fine for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Multiple worsheets in Excel document using servlets