PHP_XLSXWriter icon indicating copy to clipboard operation
PHP_XLSXWriter copied to clipboard

Sheet names break when they contain unicode characters

Open andreifatiol opened this issue 4 years ago • 0 comments

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

andreifatiol avatar Apr 09 '20 11:04 andreifatiol