PHP_XLSXWriter
PHP_XLSXWriter copied to clipboard
BUG: Sheetname loses leading/trailing spaces (which is valid)
While a sheetname can't start or end with a single quote ('), spaces are allowed, so the sanitize_sheetname function should be:
public static function sanitize_sheetname($sheetname)
{
static $badchars = '\\/?*:[]';
// static $goodchars = ' ';
// $sheetname = strtr($sheetname, $badchars, $goodchars);
// $sheetname = substr($sheetname, 0, 31);
// $sheetname = trim(trim(trim($sheetname),"'"));//trim before and after trimming single quotes
// return !empty($sheetname) ? $sheetname : 'Sheet'.((rand()%900)+100);
static $goodchars = ' ';// looks shorter than badchars due to double backslash to indicate single character
$sheetname = trim(substr(strtr($sheetname, $badchars, $goodchars),0,31),"'"); // sheetname can't start or end with single quotes
return !empty(trim($sheetname)) ? $sheetname : 'Sheet'.((rand()%900)+100); // keep leading/trailing spaces
}