Skip to content

Commit

Permalink
MDL-36845 excel export: don't output invalid sheet names.
Browse files Browse the repository at this point in the history
We should clean any proposed worksheet name, to remove the characters
that Excel does not allow.
  • Loading branch information
timhunt committed Nov 30, 2012
1 parent 47dfbd9 commit bf40455
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/excellib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/tablelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,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;
}

Expand Down

0 comments on commit bf40455

Please sign in to comment.