From f1966027379222a7b29d1bf064a212d2570710ea Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 27 Nov 2012 16:36:35 +0000 Subject: [PATCH] MDL-36845 excel export: don't output invalid sheet names. We should clean any proposed worksheet name, to remove the characters that Excel does not allow. --- lib/excellib.class.php | 7 +++++-- lib/tablelib.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/excellib.class.php b/lib/excellib.class.php index 8b1262daa3518..289b7cad11053 100644 --- a/lib/excellib.class.php +++ b/lib/excellib.class.php @@ -74,8 +74,8 @@ function MoodleExcelWorkbook($filename) { * @param string $name Name of the sheet * @return object MoodleExcelWorksheet */ - function &add_worksheet($name = '') { - /// Create the Moodle Worksheet. Returns one pointer to it + function add_worksheet($name = '') { + // Create the Moodle Worksheet. Returns one pointer to it $ws = new MoodleExcelWorksheet ($name, $this->pear_excel_workbook, $this->latin_output); return $ws; } @@ -138,6 +138,9 @@ class MoodleExcelWorksheet { */ function MoodleExcelWorksheet($name, &$workbook, $latin_output=false) { + // Replace any characters in the name that Excel cannot cope with. + $name = strtr($name, '[]*/\?:', ' '); + if (strlen($name) > 31) { // Excel does not seem able to cope with sheet names > 31 chars. // With $latin_output = false, it does not cope at all. diff --git a/lib/tablelib.php b/lib/tablelib.php index 31fdee11ca6af..4514174c815cf 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -1505,7 +1505,7 @@ function start_document($filename) { } function start_table($sheettitle) { - $this->worksheet =& $this->workbook->add_worksheet($sheettitle); + $this->worksheet = $this->workbook->add_worksheet($sheettitle); $this->rownum=0; }