Skip to content

Conversation

@Piterden
Copy link

$this->settings['w:compat'] was the string type value. Don't ask me why)

`$this->settings['w:compat']` was the `string` type value. Don't ask me why)
@troosan
Copy link
Contributor

troosan commented Nov 4, 2017

@Piterden How do you reproduce this issue exactly?

@Piterden
Copy link
Author

Piterden commented Nov 4, 2017

/**  * Class for handle user post.  */ class DownloadDocumentFile { use DispatchesJobs; /**  * The document  *  * @var DocumentInterface  */ protected $document; /**  * The document extension  *  * @var string  */ protected $extension; /**  * Formats to extensions  *  * @var array  */ protected $formats = [ 'docx' => 'Word2007', 'odt' => 'ODText', 'html' => 'HTML', 'rtf' => 'RTF', 'pdf' => 'PDF', ]; /**  * Create a new instance of DownloadDocumentFile command  *  * @param DocumentInterface $document The document  * @param string $writer The writer  */ public function __construct( DocumentInterface $document, string $extension = 'docx' ) { $this->extension = $extension; $this->document = $document; Settings::setCompatibility(false); } /**  * Handle the command  *  * @param ResponseFactory $response The response  * @return Response  */ public function handle(ResponseFactory $response) { $this->dispatch(new CreateTempFile($this->document)); $reader = IOFactory::createReader('HTML'); $parsed = $reader->load(storage_path('body.html')); $writer = IOFactory::createWriter($parsed, $this->writer()); try { $writer->save(storage_path("helloWorld.{$this->extension}")); } catch (\Exception $e) { dd($e); } return $response->download( storage_path("helloWorld.{$this->extension}") ); } /**  * Gets the extension  *  * @return string  */ protected function writer() { return array_get($this->formats, $this->extension); } }

Exactly with this code.

@troosan
Copy link
Contributor

troosan commented Nov 4, 2017

Can you give me something that I can easily run, like for instance

require_once __DIR__ . '/../bootstrap.php'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); \PhpOffice\PhpWord\Settings::setCompatibility(false); $section = $phpWord->addSection(); $section->addText('Hello World!'); $phpWord->save("helloWorld.docx", 'Word2007');

The above works fine for me by the way.

@Piterden
Copy link
Author

Piterden commented Nov 4, 2017

$reader = IOFactory::createReader('HTML'); $parsed = $reader->load(storage_path('body.html')); $writer = IOFactory::createWriter($parsed, $this->writer()); try { $writer->save(storage_path("helloWorld.{$this->extension}")); } catch (\Exception $e) { dd($e); }

This part, just replace paths.

@troosan
Copy link
Contributor

troosan commented Nov 6, 2017

@Piterden Still, the following works fine for me

@troosan
Copy link
Contributor

troosan commented Nov 6, 2017

$reader = \PhpOffice\PhpWord\IOFactory::createReader('HTML'); $parsed = $reader->load('body.html'); $writer = IOFactory::createWriter($parsed, 'Word2007'); try { $writer->save("helloWorld.docx"); } catch (\Exception $e) { var_dump($e); }

which version of PHP are you running?

@troosan
Copy link
Contributor

troosan commented Dec 4, 2017

this was actually already fixed in the develop branch

@troosan troosan closed this Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants