diff --git a/dataformat/ods/classes/writer.php b/dataformat/ods/classes/writer.php index 359aaf3e233..8f2822871d0 100644 --- a/dataformat/ods/classes/writer.php +++ b/dataformat/ods/classes/writer.php @@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base { /** @var $spouttype */ protected $spouttype = \Box\Spout\Common\Type::ODS; + /** + * Set the title of the worksheet inside a spreadsheet + * + * For some formats this will be ignored. + * + * @param string $title + */ + public function set_sheettitle($title) { + if (!$title) { + return; + } + + // Replace any characters in the name that ODS cannot cope with. + $title = strtr(trim($title, "'"), '[]*/\?:', ' '); + // Shorten the title if necessary. + $title = \core_text::substr($title, 0, 31); + // After the substr, we might now have a single quote on the end. + $title = trim($title, "'"); + + $this->sheettitle = $title; + } }