0

Thank you in advance

i want to convert HTML into DOCX so i used \PhpOffice\PhpWord library in laravel

The code for the same is as below

$html = "<html><body><h1>HELLO DEMO</h1></body></html>";
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$phpWord->save(public_path('temp/demo.docx'), 'Word2007');

instead of saving the docx, it is showing the HTML on the webpage. I want to save into a folder is there anything missed by me, i used this in laravel so require_once "vendor/autoload.php"; might not be required?

Ronak Solanki
  • 341
  • 2
  • 5
  • 14

1 Answers1

0

You need the

require_once 'vendor/autoload.php';

also add and change

$path = public_path('temp/demo.docx');
$phpWord->save($path, 'Word2007');
Dharman
  • 30,962
  • 25
  • 85
  • 135
mixaslfc
  • 49
  • 6