• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing Simple Excel File from Servlet

 
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the 1st time I've written to a file from a servlet. It's a simple task so I used "response.setContentType("application/vnd.ms-excel");". I'm readinga DB2 Table using JDBC and writing out each row to a excel spreadhseet. I first read the metadata for the column names and then I read the rest and write out one row at a time. This works great, but I need to format some of the columns ( i.e. data types and column widths etc. ) I'm trying to avoid using the jakarta poi, but will if I have to. Is there another way to format these cells ? Thanks for any help.
 
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you creating the Excel file now? As a CSV? That is unformatted, no way around that.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look into what Microsoft calls "round trip xml". It involves creating a spreadsheet in XML (with the column formats you want) and saving it as XML. This saves a ton of Microsoft formatting garbage in the XML, but it allows you to manipulate the file on the server and then send it as a download that will be recognized and opened as an Excel spreadsheet.
 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just started this task and I just assumed that "application/vnd.ms-excel" saved as xls. When I click on the link it opens up the xcel spreadsheet and when I do the save it defaults to 'tab delimited" text file.

I'm going to look into the "round trip xml" ... Thanks for the responses
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic