Merge pull request #1 from lijupm/active_sheet_support
Adding support for 'getActiveSheet' method
This commit is contained in:
commit
4610714005
@ -72,6 +72,28 @@ class SheetHelper
|
|||||||
return $sheets;
|
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 = $xmlReader->getAttribute('activeTab');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$xmlReader->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $activeSheetIndex;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of a sheet, given the XML node describing the sheet - from "workbook.xml".
|
* 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
|
* 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) */
|
/** @var int The index of the sheet being read (zero-based) */
|
||||||
protected $currentSheetIndex;
|
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 string $filePath Path of the file to be read
|
||||||
* @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
|
* @param \Box\Spout\Reader\XLSX\ReaderOptions $options Reader's current options
|
||||||
@ -32,12 +35,23 @@ class SheetIterator implements IteratorInterface
|
|||||||
// Fetch all available sheets
|
// Fetch all available sheets
|
||||||
$sheetHelper = new SheetHelper($filePath, $options, $sharedStringsHelper, $globalFunctionsHelper);
|
$sheetHelper = new SheetHelper($filePath, $options, $sharedStringsHelper, $globalFunctionsHelper);
|
||||||
$this->sheets = $sheetHelper->getSheets();
|
$this->sheets = $sheetHelper->getSheets();
|
||||||
|
$this->activeSheetIndex = $sheetHelper->getActiveSheetIndex();
|
||||||
|
|
||||||
if (count($this->sheets) === 0) {
|
if (count($this->sheets) === 0) {
|
||||||
throw new NoSheetsFoundException('The file must contain at least one sheet.');
|
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
|
* Rewind the Iterator to the first element
|
||||||
* @link http://php.net/manual/en/iterator.rewind.php
|
* @link http://php.net/manual/en/iterator.rewind.php
|
||||||
|
Loading…
x
Reference in New Issue
Block a user