From: Serguei Cambour on
Lars Christensen wrote:
> On Feb 12, 9:26�am, Jim Burgess <igsnh...(a)rub.de> wrote:
>> The program still writes 34 (without the decimal) to the cell.
>
> Excel treats 34 and 34.00 as the same number (and Ruby treat 34.0 and
> 34.00 the same).
>
> fmt = Spreadsheet::Format.new(:number_format => '0.00')
> sheet1.row(1).set_format(1,fmt)

For me, te solution:

nb_format = Spreadsheet::Format.new :number_format => '0,000'
sheet1.row(4).set_format(0, nb_format)

works fine. If you want to add decimals, just do

nb_format = Spreadsheet::Format.new :number_format => '0,000.00'
sheet1.row(4).set_format(0, nb_format)

Now the problem is that if a number to be formatted is less than 1000,
you'll get a new formatted value like that:

0,518.42

The question - how to avoid "unused" leading zeros?
Thanks
--
Posted via http://www.ruby-forum.com/.

From: Serguei Cambour on
I found a solution. To avoid leading zeros, you have to set the frmat as
follows:

nb_format = Spreadsheet::Format.new :number_format => '#,###'
sheet1.row(4).set_format(0, nb_format)

What is important - the rounding is made out of the box (1500.78 will be
formatted as 1,501, 0 will be formatted as empty cell) so no need to
write something else :)
--
Posted via http://www.ruby-forum.com/.