我试图将使用Php word格式化的HTML进行转换。
我使用summernote创建了一个HTML表单。Summernote允许用户格式化文本。此文本带有HTML标签保存到数据库中。
接下来,使用phpWord,我想将捕获的信息输出到Word文档中。请参见下面的代码:
$rational = DB::table('rationals')->where('qualificationheader_id',$qualId)->value('rational');
$wordTest = new \PhpOffice\PhpWord\PhpWord();
$newSection = $wordTest->addSection();
$newSection->getStyle()->setPageNumberingStart(1);
\PhpOffice\PhpWord\Shared\Html::addHtml($newSection,$rational);
$footer = $newSection->addFooter();
$footer->addText($curriculum->curriculum_code.'-'.$curriculum->curriculum_title);
$objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest,'Word2007');
try {
$objectWriter->save(storage_path($curriculum->curriculum_code.'-'.$curriculum->curriculum_title.'.docx'));
} catch (Exception $e) {
}
return response()->download(storage_path($curriculum->curriculum_code.'-'.$curriculum->curriculum_title.'.docx'));
保存在数据库中的文本看起来像这样:
<p class="MsoNormal"><span lang="EN-GB" style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="font-family: Arial;">The want for this qualification originated from the energy crisis in
South Africa in 2008 together with the fact that no existing qualifications
currently focuses on energy efficiency as one of the primary solutions. </span><span style="font-family: Arial;">The fact that energy supply remains under
severe pressure demands the development of skills sets that can deliver the
necessary solutions.</span><span style="font-family: Arial;"> </span><o:p></o:p></span></p><p class="MsoNormal"><span lang="EN-GB" style="background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; font-family: Arial;">This qualification addresses the need from Industry to acquire credible
and certified professionals with specialised skill sets in the energy
efficiency field. The need for this skill set has been confirmed as a global
requirement in few of the International commitment to the reduction of carbon
我收到了以下错误信息:
ErrorException (E_WARNING) DOMDocument::loadXML(): Namespace prefix o on p is not defined in Entity, line: 1