Answer the question
In order to leave comments, you need to log in
PHP: Why does the PHPWORD library throw bugs when writing addText() to a docx file?
Hello!
1) In the browser I get normal XML from the parser.
2) I'm trying to write data to a Word report (docx file). I use the PHPWord library for this. The code is the following:
$result = file_get_contents($output);
echo '<pre>';
var_dump($value);
var_dump($result);
echo '</pre>';
$section->addText($result);
$objWriter->save('helloWorld.docx');
sleep(30);
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
'"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)'
);
Answer the question
In order to leave comments, you need to log in
Figured it out, I had to add PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); before all manipulations in the code with Word. It was the XML data itself. Word "didn't understand" some of the special characters in it, as I understand it < and &. the setOutputEscapingEnabled(true) method in PHPWORD is designed to handle unread characters. As a result, I got a normal xml in a Word file. The point is small - to give normal formatting ..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question