我在 phpword 中使用 Laravel。所以在這里我想將 html 布局從刀片文件導出到 word。但是當我嘗試創建它時,出現的錯誤: DOMDocument::loadXML(): Opening and ending tag mismatch: link line 1 and head in Entity, line: 1我的代碼:$content = view('docs.index')->render();$dom = new DOMDocument();$dom->loadHTML($content);$dom->saveHTML();$phpWord = new PhpWord();Html::addHtml($phpWord->addSection(), $dom->saveHTML(), true);$objWriter = IOFactory::createWriter($phpWord, 'Word2007');$objWriter->save('doc_index_'.Carbon::now()->format('d-m-y h-i').'.docx');return view('papers.show')->with('success');這是我的刀片文件:<!DOCTYPE html><html><head> <title>Doc HTML</title> <meta charset="utf-8"> <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" /></head><body><div> <p> Laravel is a web application framework with expressive, elegant syntax. <br /> We believe development must be an enjoyable and creative experience to be truly fulfilling. <br /> Laravel takes the pain out of development by easing common tasks used in many web projects. <br /> </p></div></body></html>打印我的 $content 變量:"""<!DOCTYPE html><html><head> <title>Doc HTML</title> <meta charset="utf-8" /> <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" /></head><body><div> <p> Laravel is a web application framework with expressive, elegant syntax. <br /> We believe development must be an enjoyable and creative experience to be truly fulfilling. <br /> Laravel takes the pain out of development by easing common tasks used in many web projects. <br /> </p></div></body></html>"""
3 回答

阿晨1998
TA貢獻2037條經驗 獲得超6個贊
您的<meta>
標簽在技術上沒有關閉。要遵循省略結束標記的元素的規范,它們必須以/>
. 因此,您擁有的<br />
和<link ... />
您的元標記應該是怎樣的<meta ... />
。

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
<!DOCTYPE html>
模板開頭的部分導致了該錯誤。關于讀取樣式文件,從上面討論PHPWord/Html.php 中提供的函數詳細信息的鏈接,您可以看到 addHtml 將只使用 body 標記的內容而忽略其他所有內容。
關于上述討論中的另一個問題,我認為 PHPWord 不支持來自 css 文件的任何類型的樣式包含 - 在這個特定示例中,我不確定將引導響應式樣式應用于 word 文檔的預期結果是什么內容。
- 3 回答
- 0 關注
- 257 瀏覽
添加回答
舉報
0/150
提交
取消