/**
  * @param string $tempFilePath
  * @param XlsxSheet $sheet
  * @throws \Exception
  */
 public function appendTempFileToSheet($tempFilePath, $sheet)
 {
     $oldContent = $this->archiveHelper->getFromName($sheet->getPath());
     $anchor = '</sheetData>';
     $newContent = file_get_contents($tempFilePath);
     $newContent .= $anchor;
     if ($newContent === FALSE) {
         throw new \Exception('tempfile is not readable', 1452592557);
     }
     if (substr_count($oldContent, $anchor) !== 1) {
         throw new \Exception('could not find anchor', 1452522446);
     }
     $newFileData = str_replace($anchor, $newContent, $oldContent);
     $this->archiveHelper->deleteName($sheet->getPath());
     $this->archiveHelper->addFromString($sheet->getPath(), $newFileData);
     unlink($tempFilePath);
 }
 /**
  * @param \SimpleXMLElement $sheetData
  * @param string $relationshipTarget
  * @return void
  */
 protected function readSheetData($sheetData, $relationshipTarget)
 {
     $workbookDir = dirname($relationshipTarget) . '/';
     $attributeNamespace = $sheetData->attributes('r', TRUE);
     $sheet = new XlsxSheet();
     $sheet->setName((string) $sheetData['name']);
     $sheet->setSheetId((int) $sheetData['sheetId']);
     $this->sheets->offsetSet((string) $attributeNamespace->id, $sheet);
     $workbookRelationsXml = simplexml_load_string($this->getFromName($workbookDir . '_rels/' . basename($relationshipTarget) . '.rels'));
     foreach ($workbookRelationsXml->Relationship as $workbookRelationship) {
         if ($workbookRelationship['Type'] == self::SCHEMA_WORKSHEET) {
             $sheetId = (string) $workbookRelationship['Id'];
             /** @var XlsxSheet $sheet */
             $sheet = $this->sheets->offsetGet($sheetId);
             $sheet->setPath($workbookDir . (string) $workbookRelationship['Target']);
             $this->sheets->offsetSet($sheetId, $sheet);
         }
     }
 }
 /**
  * @test
  */
 public function setAndGetPathTest()
 {
     $path = '/test/path';
     $this->fixture->setPath($path);
     $this->assertEquals($path, $this->fixture->getPath());
 }