-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Filippo Tessarotto <zoeslam@gmail.com>
- Loading branch information
Showing
11 changed files
with
177 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/.phpunit.result.cache | ||
/composer.lock | ||
/infections.log | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSpout\Reader; | ||
|
||
/** | ||
* @template T of RowIteratorInterface | ||
* | ||
* @extends SheetInterface<T> | ||
*/ | ||
interface SheetWithMergeCellsInterface extends SheetInterface | ||
{ | ||
/** | ||
* @return list<string> Merge cells list ["C7:E7", "A9:D10"] | ||
*/ | ||
public function getMergeCells(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenSpout\Reader\XLSX; | ||
|
||
use OpenSpout\Common\Exception\IOException; | ||
use OpenSpout\Reader\Common\XMLProcessor; | ||
use OpenSpout\Reader\Wrapper\XMLReader; | ||
|
||
use function ltrim; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class SheetMergeCellsReader | ||
{ | ||
public const XML_NODE_MERGE_CELL = 'mergeCell'; | ||
public const XML_ATTRIBUTE_REF = 'ref'; | ||
|
||
/** @var list<string> Merged cells list */ | ||
private array $mergeCells = []; | ||
|
||
/** | ||
* @param string $filePath Path of the XLSX file being read | ||
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml | ||
* @param XMLProcessor $xmlProcessor Helper to process XML files | ||
*/ | ||
public function __construct( | ||
string $filePath, | ||
string $sheetDataXMLFilePath, | ||
XMLReader $xmlReader, | ||
XMLProcessor $xmlProcessor | ||
) { | ||
$sheetDataXMLFilePath = ltrim($sheetDataXMLFilePath, '/'); | ||
|
||
// Register all callbacks to process different nodes when reading the XML file | ||
$xmlProcessor->registerCallback(self::XML_NODE_MERGE_CELL, XMLProcessor::NODE_TYPE_START, [$this, 'processMergeCellsStartingNode']); | ||
$xmlReader->close(); | ||
|
||
if (false === $xmlReader->openFileInZip($filePath, $sheetDataXMLFilePath)) { | ||
throw new IOException("Could not open \"{$sheetDataXMLFilePath}\"."); | ||
} | ||
|
||
// Now read the entire header of the sheet, until we reach the <sheetData> element | ||
$xmlProcessor->readUntilStopped(); | ||
$xmlReader->close(); | ||
} | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
public function getMergeCells(): array | ||
{ | ||
return $this->mergeCells; | ||
} | ||
|
||
/** | ||
* @param XMLReader $xmlReader XMLReader object, positioned on a "<mergeCells>" starting node | ||
* | ||
* @return int A return code that indicates what action should the processor take next | ||
*/ | ||
private function processMergeCellsStartingNode(XMLReader $xmlReader): int | ||
{ | ||
$this->mergeCells[] = $xmlReader->getAttribute(self::XML_ATTRIBUTE_REF); | ||
|
||
return XMLProcessor::PROCESSING_CONTINUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.