• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Serving Excel Content

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys
I know that this question has been asked and answered many times before but I have tried all sorts.
I am trying to use a servlet to generate and present a report in Excel format. I believe that the easiest way to do this is to generate the content as an HTML table and then 'fool' the client browser into opening it in Excel by setting the Content Type etc.
This servlet works fine if I set the Content Type to "text/html" but if I set the content type to "application/vnd.ms-excel" then I get an error from Excel saying that it could not open the URL.


I am totally puzzled. Has anyone got any idea what I am doing wrong ?
Thanks
Andy
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you claim that the content type is "application/vnd.ms-excel", the browser and Excel will expect a binary stream -- the BIFF8 .xls file. You'd be better off setting the content type to "application/csv" and printing out the table as comma-separated values. Or, if you want to get really fancy, you can use Jakarta POI to generate the real thing...
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have also tried generating CSV content as follows :

But I still get the resource not found error when the content type is set to "text/csv". If I set the content type to "text\html" then the content is displayed correctly in the browser.
This is only a cut down version of the servlet that I am attempting as the content that I want to send to Excel will be generated by an XSL transfromation hence the reason why I want to use a HTML table or CSV rather than use POI or some other alternative.
Does anyone out there have a servlet that generates Excel files I can copy.
thanks
Andy
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic