Read a Number column with leading zeros using Roo gem

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 :slight_smile:

test.xlsx (4.83 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?

Just format the display however you want.

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

Colin