Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output of numbers to Excel

 
Bob Thackray
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the format of the Excel cell to text. Then it should retain the format.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wendal Park
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic