Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing Simple Excel File from Servlet  RSS feed

 
Joe Brigs
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Moores
Saloon Keeper
Posts: 3828
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you creating the Excel file now? As a CSV? That is unformatted, no way around that.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!