• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing an excel file to a ServletOutputStream  RSS feed

 
Jason Mayer
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I would like to apologize for asking this question. My googling seems to indicate that this is a very common problem, however, my googling failed me when it came to finding an answer.

I found this thread which was similar to my problem, but the solution involved using POI HSSF.

My constraint is this: I can not use any libraries not already in use in my environment. I also can not write to disc... it has to go directly to the ServletOutputStream.
My problem is this: I've not yet been able to find a way to embed an image into an excel file that doesn't require an outside library or writing to disc and then sending the file.

Here's some sample code:


output is simply a very large string

Followed by the appropriate CSS and HTML to generate the excel spreadsheet the way I want it to be seen.
This technique works great, but I've now been given the extra task of putting the company logo at the top of the spreadsheet. Can someone point me towards a solution that doesn't involve an additional library or writing the file to the server's hard drive first?

Thanks for reading, and I hope I got the correct topic (this seems to be I/O related to me)
//no preview button?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears you're producing an XML representation of the Excel document and sending that. So far, so good. Now make yourself an Excel document that has the company logo at the top, just using Excel. Save it as XML. Now you have a model for the XML that you have to send.

Make sure that the company logo is an embedded picture and not just a link to a picture on your hard drive, though. Links to an external resource don't work well when you send them to a different computer.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a hint: you can create Excel files on the web by just using HTML!

Set the response type to "application/vnd.ms-excel", and create a simple table.

Here's some code I've once written as a test, in ASP:

Here's basically what the results looks like, in Excel:

You can use regular HTML markup to set the style of cells.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!