mk-j / PHP_XLSXWriter

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

Sheet names break when they contain unicode characters #270

Closed andreifatiol closed 1 year ago

andreifatiol commented 4 years ago

Creating a sheet name that contains the character x96 (150 ascii) will cause the sheet name to be empty instead of sanitized and with that character removed.

Reproduce: make a call to writeSheetRow with : $writer->writeSheetRow('test – test', $row);

Expected: End up with a sheet name: 'test test';

Actual result: Empty sheet name

Solution: On line 760 in xlsxwriter.class.php there is a htmlspecialchars call with ENT_XML1 flag that invalidates the string and sets it empty. One of the flags (ENT_SUBSTITUTE, ENT_IGNORE) should also be added so that the bad characters are ignored and the sheet name ends up with a 'best effort' string outcome.

return strtr(htmlspecialchars($val, ENT_QUOTES | ENT_XML1 | ENT_SUBSTITUTE), $badchars, $goodchars);//strtr appears to be faster than str_replace

mk-j commented 1 year ago

fixed in master thx