PHP_XLSXWriter
PHP_XLSXWriter copied to clipboard
Sheet names break when they contain unicode characters
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