Forum: Ruby on Rails Fwd: Read a Number column with leading zeros using Roo gem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A33d5d269edd153e33826538060d1a22?d=identicon&s=25 selva4210@gmail.com (Guest)
on 2013-10-17 11:09
(Received via mailing list)
Attachment: test.xlsx (5 KB)
Hi all,

I am trying to open and read a xlsx file, which I have attached. The
upc column in that file, is the one I'm talking about. If I open the
file in the Open Office Spreadsheet, it is correctly displaying with
leading zeros. But if I read it with Roo gem it truncates the leading
zeros. I understand this is the expected behavior since the column
type is Number. But how is Open Office correctly displaying it? Is
there is way to achieve the same using Roo or any other gem?

One way I'm thinking is to patch the gem and add method which will
just return the raw content of any cell. Will this work, or anybody have
a better idea?

Thanks in Advance :)

--
Azhagu Selvan

http://tamizhgeek.in
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-10-17 11:39
(Received via mailing list)
On 17 October 2013 10:08, selva4210@gmail.com <selva4210@gmail.com>
wrote:
> One way I'm thinking is to patch the gem and add method which will
> just return the raw content of any cell. Will this work, or anybody have
> a better idea?

Just format the display however you want.

irb(main):001:0> "%03d" % 5
=> "005"

Colin
This topic is locked and can not be replied to.