MDL-56046 core: enable multiple sheets for flexible table
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user