mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-51603 dataformat: Fixed worksheet title bug
This commit is contained in:
parent
6ab41abd3e
commit
5b95105600
@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base {
|
||||
/** @var $spouttype */
|
||||
protected $spouttype = \Box\Spout\Common\Type::XLSX;
|
||||
|
||||
/**
|
||||
* 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 Excel 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,10 @@ abstract class spout_base extends \core\dataformat\base {
|
||||
$this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype);
|
||||
$filename = $this->filename . $this->get_extension();
|
||||
$this->writer->openToBrowser($filename);
|
||||
if ($this->sheettitle) {
|
||||
$sheet = $this->writer->getCurrentSheet();
|
||||
$sheet->setName($this->sheettitle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,11 +68,7 @@ abstract class spout_base extends \core\dataformat\base {
|
||||
if (!$title) {
|
||||
return;
|
||||
}
|
||||
$title = preg_replace('/[\\\\\/\\?\\*\\[\\]]/', '', $title);
|
||||
$title = substr($title, 0, 31);
|
||||
$this->sheettitle = $title;
|
||||
$sheet = $this->writer->getCurrentSheet();
|
||||
$sheet->setName($title);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user