Exemplo n.º 1
0
 /**
  * Can read exception
  *
  * @expectedException \PhpOffice\PhpWord\Exception\Exception
  */
 public function testCanReadFailed()
 {
     $object = new Word2007();
     $fqFilename = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'documents', 'foo.docx'));
     $this->assertFalse($object->canRead($fqFilename));
     $object = IOFactory::load($fqFilename);
 }
Exemplo n.º 2
0
 /**
  * Saves the result document.
  *
  * @return string
  * @throws \PhpOffice\PhpWord\Exception\Exception
  */
 public function save()
 {
     foreach ($this->temporaryDocumentHeaders as $index => $headerXML) {
         $this->zipClass->addFromString($this->getHeaderName($index), $this->temporaryDocumentHeaders[$index]);
     }
     $this->zipClass->addFromString('word/document.xml', $this->temporaryDocumentMainPart);
     $word = new Word2007();
     $read = $word->readRelationships($this->zipClass->filename);
     if (count($this->imageData)) {
         $read['document'] = array_merge($read['document'], $this->imageData);
         $xml = new \XMLWriter();
         $xml->openMemory();
         $xml->setIndent(true);
         $xml->startDocument('1.0', 'UTF-8');
         $xml->startElement('Relationships');
         $xml->startAttribute('xmlns');
         $xml->text('http://schemas.openxmlformats.org/package/2006/relationships');
         $xml->endAttribute();
         foreach ($read['document'] as $key => $data) {
             $xml->startElement('Relationship');
             $xml->startAttribute('Id');
             $xml->text($key);
             $xml->endAttribute();
             $xml->startAttribute('Type');
             $xml->text('http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $data['type']);
             $xml->endAttribute();
             $xml->startAttribute('Target');
             $xml->text($data['type'] === 'image' ? $data['docPart'] : $data['docPart'] . '.xml');
             $xml->endAttribute();
             $xml->endElement();
         }
         $xml->endElement();
         $xml->endDocument();
         $this->zipClass->addFromString('word/_rels/document.xml.rels', $xml->outputMemory(true));
     }
     foreach ($this->temporaryDocumentFooters as $index => $headerXML) {
         $this->zipClass->addFromString($this->getFooterName($index), $this->temporaryDocumentFooters[$index]);
     }
     // Close zip file
     if (false === $this->zipClass->close()) {
         throw new Exception('Could not close zip file.');
     }
     return $this->temporaryDocumentFilename;
 }
 /**
  * Can read exception
  */
 public function testCanReadFailed()
 {
     $object = new Word2007();
     $filename = __DIR__ . '/../_files/documents/foo.docx';
     $this->assertFalse($object->canRead($filename));
 }