No Description

Sample_11_ReadWord97.php 691B

12345678910111213141516171819
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // Read contents
  4. $name = basename(__FILE__, '.php');
  5. $source = "resources/{$name}.doc";
  6. echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
  7. $phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc');
  8. // (Re)write contents
  9. $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
  10. foreach ($writers as $writer => $extension) {
  11. echo date('H:i:s'), " Write to {$writer} format", EOL;
  12. $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
  13. $xmlWriter->save("{$name}.{$extension}");
  14. rename("{$name}.{$extension}", "results/{$name}.{$extension}");
  15. }
  16. include_once 'Sample_Footer.php';