I am using PHPWord library to convert my HTML template to Word.
Library link
My code to convert HTML to Word file is as below:
$phpWord = new PhpOfficePhpWordPhpWord();
$section = $phpWord->addSection();
PhpOfficePhpWordSharedHtml::addHtml($section, $htmlTemplate);
$targetFile = __DIR__ . "/1.docx";
$phpWord->save($targetFile, 'HTML');
I am facing below issues:
- I am applying background color and font color using inline style but font color is only working and background color is not working.
<p style="background-color:#FFFF00;color:#FF0000;">Some text</p>
- I am using below HTML code to allow Page break within sections of HTML templates. but it does not work in exported Word file.
<div style="page-break-after:always"><span style="display:none"> </span></div>
- I am using span tag to mark some word in bold or change the color of word in paragraph. but when i export to Word file, content after span tag, moves to new line below the word. I tried with display:inline css property in span tag. but it doesn't work.
<p>some text before span tag <span style="color:#FF0000;display:inline">XXXXX</span> Text after span tag.</p>
Edit:
Please recommend any other library which i can use to convert HTML with inline css to Word if above mentioned issues can't be resolved with PHPWord!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…