Permalink
Browse files

MDL-21446 truncate >31 char worksheet names that otherwise break Exce…

…l export.
  • Loading branch information...
1 parent 0e33a45 commit 5cf3a84aee20ce15d06a96031673637a2699a16c @timhunt timhunt committed Mar 8, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/excellib.class.php
@@ -122,7 +122,16 @@ class MoodleExcelWorksheet {
*/
function MoodleExcelWorksheet($name, &$workbook, $latin_output=false) {
- /// Internally, add one sheet to the workbook
+ 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;
/// Set encoding to UTF-16LE

0 comments on commit 5cf3a84

Please sign in to comment.