Merge da2af9283cea41227564213b08fcd93b22a79e0f into 5d4166196ad5bcde89f7316d273ef13eff144666
This commit is contained in:
commit
0457803404
@ -91,6 +91,28 @@ class SheetHelper
|
||||
return $sheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active sheet index
|
||||
*
|
||||
* @return int index of active sheet
|
||||
*/
|
||||
public function getActiveSheetIndex()
|
||||
{
|
||||
$activeSheetIndex = 0;
|
||||
|
||||
$xmlReader = new XMLReader();
|
||||
if ($xmlReader->openFileInZip($this->filePath, self::WORKBOOK_XML_FILE_PATH)) {
|
||||
while ($xmlReader->read()) {
|
||||
if ($xmlReader->isPositionedOnStartingNode('workbookView')) {
|
||||
$activeSheetIndex = (int) $xmlReader->getAttribute('activeTab');
|
||||
}
|
||||
}
|
||||
$xmlReader->close();
|
||||
}
|
||||
|
||||
return $activeSheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a sheet, given the XML node describing the sheet - from "workbook.xml".
|
||||
* We can find the XML file path describing the sheet inside "workbook.xml.res", by mapping with the sheet ID
|
||||
|
@ -20,6 +20,9 @@ class SheetIterator implements IteratorInterface
|
||||
/** @var int The index of the sheet being read (zero-based) */
|
||||
protected $currentSheetIndex;
|
||||
|
||||
/** @var int The index of the sheet which is active */
|
||||
protected $activeSheetIndex;
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the file to be read
|
||||
* @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
|
||||
@ -32,12 +35,23 @@ class SheetIterator implements IteratorInterface
|
||||
// Fetch all available sheets
|
||||
$sheetHelper = new SheetHelper($filePath, $options, $sharedStringsHelper, $globalFunctionsHelper);
|
||||
$this->sheets = $sheetHelper->getSheets();
|
||||
$this->activeSheetIndex = $sheetHelper->getActiveSheetIndex();
|
||||
|
||||
if (count($this->sheets) === 0) {
|
||||
throw new NoSheetsFoundException('The file must contain at least one sheet.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve active sheet
|
||||
*
|
||||
* @return Sheet
|
||||
*/
|
||||
public function getActiveSheet()
|
||||
{
|
||||
return $this->sheets[$this->activeSheetIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the Iterator to the first element
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
|
Loading…
x
Reference in New Issue
Block a user