MDL-76219 lib: Change Box\Spout to OpenSpout library

This commit is contained in:
Meirza 2022-11-24 16:37:25 +07:00
parent b2b17b9d9b
commit 93220a66f5
7 changed files with 19 additions and 17 deletions

View File

@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".csv";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::CSV;
protected $spouttype = \OpenSpout\Common\Type::CSV;
}

View File

@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".xlsx";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::XLSX;
protected $spouttype = \OpenSpout\Common\Type::XLSX;
/**
* Set the title of the worksheet inside a spreadsheet

View File

@ -57,15 +57,15 @@ class writer_test extends \advanced_testcase {
$file = tempnam(sys_get_temp_dir(), 'excel_');
$handle = fopen($file, "w");
fwrite($handle, $content);
/** @var \Box\Spout\Reader\XLSX\Reader $reader */
$reader = \Box\Spout\Reader\Common\Creator\ReaderFactory::createFromType(\Box\Spout\Common\Type::XLSX);
/** @var \OpenSpout\Reader\XLSX\Reader $reader */
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromType(\OpenSpout\Common\Type::XLSX);
$reader->open($file);
/** @var \Box\Spout\Reader\XLSX\Sheet[] $sheets */
/** @var \OpenSpout\Reader\XLSX\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \Box\Spout\Common\Entity\Row[] $rows */
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];

View File

@ -42,7 +42,7 @@ class writer extends \core\dataformat\spout_base {
protected $extension = ".ods";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::ODS;
protected $spouttype = \OpenSpout\Common\Type::ODS;
/**
* Set the title of the worksheet inside a spreadsheet

View File

@ -51,20 +51,20 @@ class writer_test extends \advanced_testcase {
* Get ods rows from binary content
* @param string $content
* @return array
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \OpenSpout\Common\Exception\IOException
* @throws \OpenSpout\Reader\Exception\ReaderNotOpenedException
*/
private function get_ods_rows_content($content) {
$reader = \Box\Spout\Reader\Common\Creator\ReaderFactory::createFromType(\Box\Spout\Common\Type::ODS);
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromType(\OpenSpout\Common\Type::ODS);
$file = tempnam(sys_get_temp_dir(), 'ods_');
$handle = fopen($file, "w");
fwrite($handle, $content);
$reader->open($file);
/** @var \Box\Spout\Reader\ODS\Sheet[] $sheets */
/** @var \OpenSpout\Reader\ODS\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \Box\Spout\Common\Entity\Row[] $rows */
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];

View File

@ -51,7 +51,7 @@ abstract class spout_base extends \core\dataformat\base {
* Output file headers to initialise the download of the file.
*/
public function send_http_headers() {
$this->writer = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
$this->writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
if (method_exists($this->writer, 'setTempFolder')) {
$this->writer->setTempFolder(make_request_directory());
}
@ -70,7 +70,7 @@ abstract class spout_base extends \core\dataformat\base {
* 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);
$this->writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createWriter($this->spouttype);
if (method_exists($this->writer, 'setTempFolder')) {
$this->writer->setTempFolder(make_request_directory());
}
@ -100,7 +100,7 @@ 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\WriterMultiSheetsAbstract) {
if ($this->sheettitle && $this->writer instanceof \OpenSpout\Writer\WriterMultiSheetsAbstract) {
if ($this->renamecurrentsheet) {
$sheet = $this->writer->getCurrentSheet();
$this->renamecurrentsheet = false;
@ -109,7 +109,7 @@ abstract class spout_base extends \core\dataformat\base {
}
$sheet->setName($this->sheettitle);
}
$row = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray((array)$columns);
$row = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray((array)$columns);
$this->writer->addRow($row);
}
@ -120,7 +120,7 @@ abstract class spout_base extends \core\dataformat\base {
* @param int $rownum
*/
public function write_record($record, $rownum) {
$row = \Box\Spout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($this->format_record($record));
$row = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray($this->format_record($record));
$this->writer->addRow($row);
}

View File

@ -90,4 +90,6 @@ $renamedclasses = [
'core_cohort\\local\\entities\\cohort' => 'core_cohort\\reportbuilder\\local\\entities\\cohort',
'core_cohort\\local\\entities\\cohort_member' => 'core_cohort\\reportbuilder\\local\\entities\\cohort_member',
'core_block\\local\\views\\secondary' => 'core_block\\navigation\\views\\secondary',
// Since Moodle 4.2.
'Box\\Spout' => 'OpenSpout',
];