kasparsd / mini-sheets-php

Library for creating the most basic Office Open XML and Excel XLSX files.
https://kaspars.net/blog/excel-xlsx-xml-php
MIT License
11 stars 0 forks source link

FIX: store numeric values in cells #1

Open tobwen opened 4 years ago

tobwen commented 4 years ago

What's the issue?

Currently, numerical values cannot be stored in columns. The reason is that numbers incorrectly end up in "shared strings" and their indexes are ending up in the cell - not the values itself.

Want a quick fix?

change this https://github.com/kasparsd/mini-sheets-php/blob/16e283906e7d38184025e88f1b42d6b7d7433baa/src/XlsxBuilder.php#L78-L83

into that

$cells[] = sprintf(
    '<c r="%s" t="%s"><v>%s</v></c>',
    $this->escape_xml( $this->xlsx_cell_name( $row_no, $col_no ) ),
    $this->escape_xml( $field_type ),
    $this->escape_xml( $field_type === 'n' ? $field_value : $field_value_no )
);

Make it even better

Put the creation of $field_value_no into an else clause.

Tropicalista commented 3 years ago

I have same problem. Number are shown as 0 in cells. Will this fix be approved?