Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
<?php

namespace PhpOffice\PhpSpreadsheet\Reader;

> use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner; use PhpOffice\PhpSpreadsheet\Shared\File;
> use PhpOffice\PhpSpreadsheet\Spreadsheet;
abstract class BaseReader implements IReader { /** * Read data only? * Identifies whether the Reader should only read data values for cells, and ignore any formatting information; * or whether it should read both data and formatting. * * @var bool */ protected $readDataOnly = false; /** * Read empty cells? * Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing * null value or empty string. * * @var bool */ protected $readEmptyCells = true; /** * Read charts that are defined in the workbook? * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;. * * @var bool */ protected $includeCharts = false; /** * Restrict which sheets should be loaded? * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded. *
< * @var array of string
> * @var null|string[]
*/ protected $loadSheetsOnly; /** * IReadFilter instance. * * @var IReadFilter */ protected $readFilter;
> /** @var resource */
protected $fileHandle; /**
< * @var XmlScanner
> * @var ?XmlScanner
*/ protected $securityScanner; public function __construct() { $this->readFilter = new DefaultReadFilter(); } public function getReadDataOnly() { return $this->readDataOnly; }
< public function setReadDataOnly($pValue)
> public function setReadDataOnly($readCellValuesOnly)
{
< $this->readDataOnly = (bool) $pValue;
> $this->readDataOnly = (bool) $readCellValuesOnly;
return $this; } public function getReadEmptyCells() { return $this->readEmptyCells; }
< public function setReadEmptyCells($pValue)
> public function setReadEmptyCells($readEmptyCells)
{
< $this->readEmptyCells = (bool) $pValue;
> $this->readEmptyCells = (bool) $readEmptyCells;
return $this; } public function getIncludeCharts() { return $this->includeCharts; }
< public function setIncludeCharts($pValue)
> public function setIncludeCharts($includeCharts)
{
< $this->includeCharts = (bool) $pValue;
> $this->includeCharts = (bool) $includeCharts;
return $this; } public function getLoadSheetsOnly() { return $this->loadSheetsOnly; }
< public function setLoadSheetsOnly($value)
> public function setLoadSheetsOnly($sheetList)
{
< if ($value === null) {
> if ($sheetList === null) {
return $this->setLoadAllSheets(); }
< $this->loadSheetsOnly = is_array($value) ? $value : [$value];
> $this->loadSheetsOnly = is_array($sheetList) ? $sheetList : [$sheetList];
return $this; } public function setLoadAllSheets() { $this->loadSheetsOnly = null; return $this; } public function getReadFilter() { return $this->readFilter; }
< public function setReadFilter(IReadFilter $pValue)
> public function setReadFilter(IReadFilter $readFilter)
{
< $this->readFilter = $pValue;
> $this->readFilter = $readFilter;
return $this; }
< public function getSecurityScanner()
> public function getSecurityScanner(): ?XmlScanner
{ return $this->securityScanner; }
> public function getSecurityScannerOrThrow(): XmlScanner /** > { * Open file for reading. > if ($this->securityScanner === null) { * > throw new ReaderException('Security scanner is unexpectedly null'); * @param string $pFilename > } */ > protected function openFile($pFilename): void > return $this->securityScanner; { > } if ($pFilename) { > File::assertFile($pFilename); > protected function processFlags(int $flags): void > { // Open file > if (((bool) ($flags & self::LOAD_WITH_CHARTS)) === true) { $fileHandle = fopen($pFilename, 'rb'); > $this->setIncludeCharts(true); } else { > } $fileHandle = false; > if (((bool) ($flags & self::READ_DATA_ONLY)) === true) { } > $this->setReadDataOnly(true); if ($fileHandle !== false) { > } $this->fileHandle = $fileHandle; > if (((bool) ($flags & self::SKIP_EMPTY_CELLS) || (bool) ($flags & self::IGNORE_EMPTY_CELLS)) === true) { } else { > $this->setReadEmptyCells(false); throw new ReaderException('Could not open file ' . $pFilename . ' for reading.'); > } } > } } > } > protected function loadSpreadsheetFromFile(string $filename): Spreadsheet > { > throw new PhpSpreadsheetException('Reader classes must implement their own loadSpreadsheetFromFile() method'); > } >
< * Open file for reading.
> * Loads Spreadsheet from file.
< * @param string $pFilename
> * @param int $flags the optional second parameter flags may be used to identify specific elements > * that should be loaded, but which won't be loaded by default, using these values: > * IReader::LOAD_WITH_CHARTS - Include any charts that are defined in the loaded file
< protected function openFile($pFilename): void
> public function load(string $filename, int $flags = 0): Spreadsheet
< if ($pFilename) { < File::assertFile($pFilename);
> $this->processFlags($flags);
< // Open file < $fileHandle = fopen($pFilename, 'rb'); < } else {
> try { > return $this->loadSpreadsheetFromFile($filename); > } catch (ReaderException $e) { > throw $e; > } > } > > /** > * Open file for reading. > */ > protected function openFile(string $filename): void > {
> if ($filename) { > File::assertFile($filename); > > // Open file > $fileHandle = fopen($filename, 'rb');
< if ($fileHandle !== false) { < $this->fileHandle = $fileHandle; < } else { < throw new ReaderException('Could not open file ' . $pFilename . ' for reading.');
> if ($fileHandle === false) { > throw new ReaderException('Could not open file ' . $filename . ' for reading.');
> > $this->fileHandle = $fileHandle;