readFilter = new DefaultReadFilter(); } public function getReadDataOnly(): bool { return $this->readDataOnly; } public function setReadDataOnly(bool $readCellValuesOnly): self { $this->readDataOnly = $readCellValuesOnly; return $this; } public function getReadEmptyCells(): bool { return $this->readEmptyCells; } public function setReadEmptyCells(bool $readEmptyCells): self { $this->readEmptyCells = $readEmptyCells; return $this; } public function getIgnoreRowsWithNoCells(): bool { return $this->ignoreRowsWithNoCells; } public function setIgnoreRowsWithNoCells(bool $ignoreRowsWithNoCells): self { $this->ignoreRowsWithNoCells = $ignoreRowsWithNoCells; return $this; } public function getIncludeCharts(): bool { return $this->includeCharts; } public function setIncludeCharts(bool $includeCharts): self { $this->includeCharts = $includeCharts; return $this; } /** @return null|string[] */ public function getLoadSheetsOnly(): ?array { return $this->loadSheetsOnly; } /** @param null|string|string[] $sheetList */ public function setLoadSheetsOnly(string|array|null $sheetList): self { if ($sheetList === null) { return $this->setLoadAllSheets(); } $this->loadSheetsOnly = is_array($sheetList) ? $sheetList : [$sheetList]; return $this; } public function setLoadAllSheets(): self { $this->loadSheetsOnly = null; return $this; } public function getReadFilter(): IReadFilter { return $this->readFilter; } public function setReadFilter(IReadFilter $readFilter): self { $this->readFilter = $readFilter; return $this; } public function getSecurityScanner(): ?XmlScanner { return $this->securityScanner; } public function getSecurityScannerOrThrow(): XmlScanner { if ($this->securityScanner === null) { throw new ReaderException('Security scanner is unexpectedly null'); } return $this->securityScanner; } protected function processFlags(int $flags): void { if (((bool) ($flags & self::LOAD_WITH_CHARTS)) === true) { $this->setIncludeCharts(true); } if (((bool) ($flags & self::READ_DATA_ONLY)) === true) { $this->setReadDataOnly(true); } if (((bool) ($flags & self::IGNORE_EMPTY_CELLS)) === true) { $this->setReadEmptyCells(false); } if (((bool) ($flags & self::IGNORE_ROWS_WITH_NO_CELLS)) === true) { $this->setIgnoreRowsWithNoCells(true); } } protected function loadSpreadsheetFromFile(string $filename): Spreadsheet { throw new PhpSpreadsheetException('Reader classes must implement their own loadSpreadsheetFromFile() method'); } /** * Loads Spreadsheet from file. * * @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 */ public function load(string $filename, int $flags = 0): Spreadsheet { $this->processFlags($flags); try { return $this->loadSpreadsheetFromFile($filename); } catch (ReaderException $e) { throw $e; } } /** * Open file for reading. */ protected function openFile(string $filename): void { $fileHandle = false; if ($filename) { File::assertFile($filename); // Open file $fileHandle = fopen($filename, 'rb'); } if ($fileHandle === false) { throw new ReaderException('Could not open file ' . $filename . ' for reading.'); } $this->fileHandle = $fileHandle; } /** * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns). * * @return array */ public function listWorksheetInfo(string $filename): array { throw new PhpSpreadsheetException('Reader classes must implement their own listWorksheetInfo() method'); } /** * Returns names of the worksheets from a file, * possibly without parsing the whole file to a Spreadsheet object. * Readers will often have a more efficient method with which * they can override this method. * * @return string[] */ public function listWorksheetNames(string $filename): array { $returnArray = []; $info = $this->listWorksheetInfo($filename); foreach ($info as $infoArray) { $returnArray[] = $infoArray['worksheetName']; } return $returnArray; } public function getValueBinder(): ?IValueBinder { return $this->valueBinder; } public function setValueBinder(?IValueBinder $valueBinder): self { $this->valueBinder = $valueBinder; return $this; } protected function newSpreadsheet(): Spreadsheet { return new Spreadsheet(); } }