MDL-68500 dataformat: allow instances to export to local file.

This commit is contained in:
Paul Holden
2020-05-04 09:32:44 +01:00
parent cd391f9922
commit 1de3b81983
6 changed files with 262 additions and 11 deletions
+28
View File
@@ -66,6 +66,23 @@ abstract class spout_base extends \core\dataformat\base {
$this->renamecurrentsheet = true;
}
/**
* Set the dataformat to be output to current file
*/
public function start_output_to_file(): void {
$this->writer = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
if (method_exists($this->writer, 'setTempFolder')) {
$this->writer->setTempFolder(make_request_directory());
}
$this->writer->openToFile($this->filepath);
// By default one sheet is always created, but we want to rename it when we call start_sheet().
$this->renamecurrentsheet = true;
$this->start_output();
}
/**
* Set the title of the worksheet inside a spreadsheet
*
@@ -114,4 +131,15 @@ abstract class spout_base extends \core\dataformat\base {
$this->writer->close();
$this->writer = null;
}
/**
* Write data to disk
*
* @return bool
*/
public function close_output_to_file(): bool {
$this->close_output();
return true;
}
}