php - PHPWord table boder not working and Word file error when open
Get the solution ↓↓↓I'm trying to combine WYSIWYG and PHPWord.
But I have two problem
- the html table border disappear in created Word file.
- Created Word file will have error messages saying the file is corrupted or something, but still readable.
Here is my code:
use PhpOffice\PhpWord\IOFactory;
$html = '
<table class="MsoTableGrid" style="width: 100.0%; border-collapse: collapse;" border="1" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 414.8pt; border: solid windowtext 1.0pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="707">
<p style="text-align: right; margin: 0cm 0cm 0.0001pt; font-size: 10.5pt; font-family: Century, serif;" align="right">Date:2020/9/10</p>
<p style="margin: 0cm 0cm 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Century, serif;"> I luv Shishiro Botan</p>
<p style="text-align: center; margin: 0cm 0cm 0.0001pt; font-size: 10.5pt; font-family: Century, serif;" align="center"><span style="font-size: 18.0pt;">Mai Waifu Shishiro Botan!</span></p>
<p style="text-indent: 14pt; margin: 0cm 0cm 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Century, serif;"><span style="font-size: 14.0pt;">UwU</span></p>
<p style="text-align: center; margin: 0cm 0cm 0.0001pt; font-size: 10.5pt; font-family: Century, serif;" align="center"><u><span style="font-size: 14.0pt;">Change my mind</span></u></p>
<p style="margin: 0cm 0cm 0.0001pt 10.5pt; text-align: justify; font-size: 10.5pt; font-family: Century, serif;">You can try but I wont buy:D</p>
</td>
</tr>
</tbody>
</table>
';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
$filename = "test";
header("Content-Type: application/vnd.ms-word");
header('Content-Disposition: attachment;filename="' . $filename . '.docx"');
$objWriter = IOFactory::createWriter($phpWord);
$objWriter->save('php://output');
The Html content is copy directly from WYSIWYG.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the requested url was not found on this server. xampp
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.