jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Exporting HTML-Table data to EXCEL sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Exporting HTML-Table data to EXCEL sheet" Watch "Exporting HTML-Table data to EXCEL sheet" New topic
Author

Exporting HTML-Table data to EXCEL sheet

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
Hi,

I have a JSP cantian, Header,footer and a HTML table which is dynamically generated from the previous page.
I am trying to export that HTML table data to a EXCEL sheet.

I placed the above code in my JSP. Its generating Excel sheet with Header, table, and Footer(but its not showing the result page).

But My application needs,
After displaying the result page(Result page cantains Header, Footer and HTML table) , I have a link "Export to Excel" .
Once I click that link it should generate a Excel sheet with only HTML Table contents.(Not with all)
Is there any speicfic way to do that. Please suggest me some way.

Thanks in advance,
-Mark
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

cantian?

You can't mix the two responses in the same request. See this recent similar post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
JSP page only contains one HTML table with 6 columns, lets say (column1,2,3,4,5,6), I placed a hyperlink to column1 to show the deaials of that record(Table contains 100's of records).

I need to place a button at the bottom of the table "EXPORT TO EXCEL".
When I click that button, The data in the HTML Table(100's of records )should export to EXCEL sheet without reloding the page and user be able to save that excel sheet.

Once user saved the excel sheet, then if he wants to view the record details then he will click on the hyperlink(column 1) and view the details.

how to achieve this functionality EXPORT TO EXCEL with button?
Please suggest me.
-Mark
Rajeev Desh
Greenhorn

Joined: Sep 05, 2008
Posts: 4
Hi Mark,
You can have a jsp file that displays results along with a button
"export to excel" upon clicking this, call another jsp with appropriate html format(hope you would do that) that you want to show in excel sheet, say "export_to_excel.jsp".
"& lt;" input type='button' value='Export To Excel' "& lt;" on click="javascript:window.location.href='export_to_excel.jsp ""& lt;"

you can create a jsp file export_to_excel.jsp and set the response like:
response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");

upon clicking the button, you will see a dialogue box asking to save or display ...
that will be self explainatory!

cheers....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Except, of course, that doesn't do anything to create an excel file -- it only tells the browser that the response should be such a file.
 
 
subject: Exporting HTML-Table data to EXCEL sheet
 
Similar Threads
Exporting html data to excel
jsp to Excel using JExcel
Export JSP page's content to an Excel Spread Sheet
can we export the data from jsp page to a excel sheet with out a database hit
display of japanese characters in excel sheet