mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

Example ex03-styles.php fails with error in Excel 2007 #288

Closed peteshew closed 3 years ago

peteshew commented 4 years ago

The code in writeSheetRow to handle row options sets values to false or true in some cases. Looking at the non row option code just below, these should be set to "false" or "true" including the quotes as string values not boolean ones.

Without this change, using row options always causes an error when loading the resultant xlsx into Excel 2007 as it doesn't seem to like empty values which is what results, e.g. hidden="" rather than hidden="false"

I suspect that the casting to (bool) may also cause problems but I haven' t yet been there as I am not sure how the hidden and collapsed options are specified (or even what they mean).

AzzaAzza69 commented 3 years ago

In ended up fixing this myself:

private function boolToStr($value){
    return $value ? 'true' : 'false';
}

...
$sheet->file_writer->write('<row collapsed="'.$this->boolToStr($collapsed).
    '" customHeight="'.$this->boolToStr($customHt).
    '" hidden="'.$this->boolToStr($hidden).
    '" ht="'.($ht).
    '" outlineLevel="0" r="' . ($sheet->row_count + 1) . '">');
peteshew commented 3 years ago

A more elegant solution then mine, but the effect is the same.