From 0484f1ef01766fa3a1e0f7a259935ae7799f0dee Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 8 Mar 2011 16:52:38 +0000 Subject: [PATCH] MDL-21446 truncate >31 char worksheet names that otherwise break Excel export. --- lib/excellib.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/excellib.class.php b/lib/excellib.class.php index 1addd11499b..def025c74ab 100644 --- a/lib/excellib.class.php +++ b/lib/excellib.class.php @@ -138,6 +138,15 @@ class MoodleExcelWorksheet { */ function MoodleExcelWorksheet($name, &$workbook, $latin_output=false) { + 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. + // With $latin_output = true it is supposed to work, but in our experience, + // it doesn't. Therefore, truncate in all circumstances. + $textlib = textlib_get_instance(); + $name = $textlib->substr($name, 0, 31); + } + /// Internally, add one sheet to the workbook $this->pear_excel_worksheet =& $workbook->addWorksheet($name); $this->latin_output = $latin_output;