• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JSP to Excel - beginner

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a search function(JSP) which upon submit returns results to itself in a HTML table. I would like to give my users the ability to save the report in excel via button click.

From searching the forums, I have been able to piece together bits of how to do this. However, I am slightly confused on how to send the HTML section to printed.







fooTwo form calls a servlet:



In the above code, if I use the set tag around the HTML written the results will not display on JSP page. However, If I click the open excel button - the proper results are there. I realize this is because I am setting the html as the value of foo. But I need the results displayed on the JSP and then if needed in excel.

I have a feeling this is pretty dumb but I am stumped as to how I should do this. Any advice/direction would greatly be appreciated.

Thanks,
Crystal
 
Marshal
Posts: 28293
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So first you want your output to be HTML that is displayed in the user's browser? And you want to have a button in the browser that saves the HTML as Excel?

I'm not aware of anything built into browsers that allows them to save what they are displaying in Excel format. So you need two ways of outputting your results. One way outputs the HTML, including a button that requests the second way. The second way outputs the data as Excel in an attachment, and I see you already know how to do that. Just don't try to do both at once.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Crystal Bazil:
I have a search function(JSP) which upon submit returns results to itself in a HTML table. I would like to give my users the ability to save the report in excel via button click.

From searching the forums, I have been able to piece together bits of how to do this. However, I am slightly confused on how to send the HTML section to printed.







fooTwo form calls a servlet:



In the above code, if I use the set tag around the HTML written the results will not display on JSP page. However, If I click the open excel button - the proper results are there. I realize this is because I am setting the html as the value of foo. But I need the results displayed on the JSP and then if needed in excel.

I have a feeling this is pretty dumb but I am stumped as to how I should do this. Any advice/direction would greatly be appreciated.

Thanks,
Crystal



Hi Crystal,

I have been working on transporting data out from a database to excel, which is kind of related to the question you are asking.

Firstly, i think you should let us know what kind of framework you are using for your site..

Anyway, i reckon that to work around for your problem, you must either get an API to help out with. You can either use JExcel API(www.andykhan.com/jexcel) or POI, which is a package, to help you achieve the result of exporting the data into the Excel format. As for what i understand through my own experience, your solution should come in two parts.

Firstly, you should just populate the results out in the servlet. You can simply get a servlet to "talk" to the JSP and transport the data. Which means, under the MVC model, Control -> View layer...

Next, to exporting the data, you could just simply write an action(Struts) class to support this functionality..

This is how you should split the classes.. do let me know if you need further help..
 
Crystal Bazil
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a solution albeit a janky one.

I split my reportSearch.jsp into three pages. Instead of having the results post to reportSearch I am doing the following:



Variable foo is then set to the generated HTML of reportExcel. When I call my servlet to display HTML in Excel, it opens a new attachment with formatted HTML, including styles and all. I am not sure how well this would work for big reports but it will do until I find a better solution.

Thanks,
Crystal

// edit to disabled psycho smiley

[ December 16, 2005: Message edited by: Crystal Bazil ]

[ December 16, 2005: Message edited by: Crystal Bazil ]
[ December 16, 2005: Message edited by: Crystal Bazil ]
 
Aaron Ting
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Crystal Bazil:
I have a solution albeit a janky one.

I split my reportSearch.jsp into three pages. Instead of having the results post to reportSearch I am doing the following:



Variable foo is then set to the generated HTML of reportExcel. When I call my servlet to display HTML in Excel, it opens a new attachment with formatted HTML, including styles and all. I am not sure how well this would work for big reports but it will do until I find a better solution.

Thanks,
Crystal

// edit to disabled psycho smiley

[ December 16, 2005: Message edited by: Crystal Bazil ]

[ December 16, 2005: Message edited by: Crystal Bazil ]

[ December 16, 2005: Message edited by: Crystal Bazil ]



Cool. Cheers!
 
Evildoers! Eat my justice! And this tiny ad's justice too!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic