File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Output of numbers to Excel

Bob Thackray

Joined: Jun 17, 2003
Posts: 1
I am using
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 ?
Cindy Glass
"The Hood"

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

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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:
subject: Output of numbers to Excel
It's not a secret anymore!