glebm / to_spreadsheet

Render XLSX from Rails using existing views (html ⇒ xlsx)
Other
91 stars 37 forks source link

Quotes in front of numbers #3

Closed emiellohr closed 12 years ago

emiellohr commented 12 years ago

Hi glemb,

I'm using your gem which is handy, thanks! I've got one issue... all my numbers are preceded with a single quote.

My versions are: to_spreadsheet (0.9) spreadsheet (0.6.5.9)

The generated html is:

  <table cellpadding='0' cellspacing='0' class='list'>
    <caption>Omzet rapportage</caption>
    <thead>
      <tr>
        <th>Orderdatum</th>
        <th>Ordernr</th>
        <th>Evenement</th>
        <th>Omschrijving</th>
        <th>Aantal</th>
        <th>Prijs</th>
        <th>Totaal</th>
      </tr>
    </thead>
    <tbody>
      <tr class='odd'>
        <td class='date'>04-03-2012</td>
        <td>867</td>
        <td>Snowxxx</td>
        <td>2 uur fadss afdafdsnen</td>
        <td class='int'>1</td>
        <td>31,95</td>
        <td>31,95</td>
      </tr>

In the cells I find the text fields are okay, but the date and number fields are: '31,95 and '04-03-2012

Any clue?

glebm commented 12 years ago

I'll take a look and try to reproduce this weekend, please keep me updated

emiellohr commented 12 years ago

I'm using Ruby 1.9. And for spreadsheet 1.0, Ruby 1.9 support is announced...

== Roadmap

0.7.0:: Improved Format support/Styles 0.7.1:: Document Modification: Formats/Styles 0.8.0:: Formula Support 0.8.1:: Document Modification: Formulas 0.9.0:: Write-Support: BIFF5 1.0.0:: Ruby 1.9 Support; Remove backward compatibility code

Could that be the problem? Any ideas?

glebm commented 12 years ago

I don't think that's the problem, as I'm using 1.9 as well Does OpenOffice show the same results as Microsoft Office?

Just an idea, try replacing 'int' with "int" (double quotes instead of single quotes)

emiellohr commented 12 years ago

Yes, Excel & OpenOffice are both the same.

The quote trick didn't make any difference. :-(

I just played with the classes but it doesn't seem to matter. All numeric values are prefixed with the quote.

glebm commented 12 years ago

I've just tried, and I cannot reproduce the problem. Could it be your regional settings?

emiellohr commented 12 years ago

I rewrote the haml to plain erb/html and now all goes fine, exept for rounded float values, such as 10.0, 7.0, ... They are still converted to text with leading quote. Maybe we need formatting here??

fmt = Spreadsheet::Format.new(:number_format => '0.00')
sheet1.row(1).set_format(1,fmt)
glebm commented 12 years ago

So rewriting HAML helped? Could you please post the original HAML here

emiellohr commented 12 years ago

No, it had nothing to do with the Haml.... You parse the generated html using nokogiri and based on the class you add an extra typecast. For fixnum values this works. For floats (no conversion) this also works, except for round float values, such as "7.0", or "10.0". These are interpeted as text (and prefixed with single quote). You should be able to reproduce this.

glebm commented 12 years ago

I see. However in your example typed ints and dates were getting the ' (td class='int') -- still can't reproduce that

emiellohr commented 12 years ago

No, me neither. I can't recall on what changed.

glebm commented 12 years ago

OK. Version 0.9.3 with float format support is now out!

emiellohr commented 12 years ago

Okay, thanks!