使用了以上这个库将docx
转成html
,发现部分样式丢失,并有有单词莫名换行。再将html
转docx
就变不回原来那样了,有人遇过这种情况么。。
代码如下
$objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
$objPHPFile = $objReader->load('123.docx');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($objPHPFile, 'HTML');
echo $objWriter->save('test.html');
$objReader = \PhpOffice\PhpWord\IOFactory::createReader('HTML');
//var_dump($objReader);exit();
$objPHPFile = $objReader->load('test.html');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($objPHPFile, 'Word2007');
echo $objWriter->save('test2.docx');
用libreoffice,把Word文档转成HTML,可以保持大部分样式.
在Ubuntu服务器上安装libreoffice:
apt install libreoffice-writer