MDL-56046 core: enable multiple sheets for flexible table

This commit is contained in:
Mark Nelson
2017-06-26 13:55:21 +08:00
parent a54703d88f
commit 4e50a38018
2 changed files with 39 additions and 15 deletions
+15 -7
View File
@@ -44,6 +44,9 @@ abstract class spout_base extends \core\dataformat\base {
/** @var $sheettitle */
protected $sheettitle;
/** @var $renamecurrentsheet */
protected $renamecurrentsheet = false;
/**
* Output file headers to initialise the download of the file.
*/
@@ -54,10 +57,9 @@ abstract class spout_base extends \core\dataformat\base {
}
$filename = $this->filename . $this->get_extension();
$this->writer->openToBrowser($filename);
if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\AbstractMultiSheetsWriter) {
$sheet = $this->writer->getCurrentSheet();
$sheet->setName($this->sheettitle);
}
// By default one sheet is always created, but we want to rename it when we call start_sheet().
$this->renamecurrentsheet = true;
}
/**
@@ -68,9 +70,6 @@ abstract class spout_base extends \core\dataformat\base {
* @param string $title
*/
public function set_sheettitle($title) {
if (!$title) {
return;
}
$this->sheettitle = $title;
}
@@ -80,6 +79,15 @@ abstract class spout_base extends \core\dataformat\base {
* @param array $columns
*/
public function start_sheet($columns) {
if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\AbstractMultiSheetsWriter) {
if ($this->renamecurrentsheet) {
$sheet = $this->writer->getCurrentSheet();
$this->renamecurrentsheet = false;
} else {
$sheet = $this->writer->addNewSheetAndMakeItCurrent();
}
$sheet->setName($this->sheettitle);
}
$this->writer->addRow(array_values((array)$columns));
}