File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Output of numbers to Excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Output of numbers to Excel" Watch "Output of numbers to Excel" New topic
Author

Output of numbers to Excel

Bob Thackray
Greenhorn

Joined: Jun 17, 2003
Posts: 1
Hi,
I am using
setContentType("application/msexcel")
to direct output to an excel spreadsheet for display. This works fine for text fields, but all fields that it thinks are numbers are truncated, ie:
000200 becumes 200
I need to display this as a text field ( as 000200).
I have tried prefixing the string with a single ' but this just displays in excel as a character.
How do I format the fells as text ?
Thanks.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Try setting the format of the Excel cell to text. Then it should retain the format.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31101
    
165

If you use a library to create the Excel spreadsheet, you can specify the cell format. I've used HSSF (horrible spreadsheet format) which is available from Apache.
HSSF


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Wendal Park
Ranch Hand

Joined: Aug 28, 2001
Posts: 39
There is an ugly solution ... well I should say a "close-enough" solution:
Try to wrap any fields (text) with either '' or "", then automatically Excel will treat them as normal text and display them as they are. But unfortunately they would appear as "000200" in the cells showing also the quotes.
But if you can bear with this, then you don't spend extra time in learning to use a new package.


MSc, BSc, SCJP 1.4<br /> <img src="graemlins/banghead.gif" border="0" alt="[banghead]" /> SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Output of numbers to Excel