save('./ceshi.htm');"."/> save('./ceshi.htm');".">
Home > Article > Backend Development > How to convert uploaded word files to Html format with PHP
How to convert php word into html: first install PHPOffice through composer; then check the vendor folder; finally convert word through "$xmlWriter ->save('./ceshi.htm');" Convert the file to Html format.
Recommended: "PHP Video Tutorial"
Method 1: Through PHPOffice (recommended )
1: composer require phpoffice/phpword /* 通过composer安装 PHPOffice 需要科学上网 或者用中国镜像:https://www.phpcomposer.com/ */ 2: 安装成功可看到 vendor文件夹 3: 使用方法 : <?php require 'vendor/autoload.php'; $phpWord = \PhpOffice\PhpWord\IOFactory::load('./4.docx'); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML"); $xmlWriter ->save('./ceshi.htm'); 4:官方 /* 官方案例:https://phpword.readthedocs.io/en/latest/general.html github: https://github.com/PHPOffice/PhpSpreadsheet */
Method 2: Through python
from win32com import client as wc import sys def saveHtm(): # print(wordPath) # print(htmPath) wordPath='E:/1.doc' htmPath='E:/1.htm' word = wc.Dispatch('Word.Application') print(word) doc = word.Documents.Open('E:/1.doc') doc.SaveAs("E:/1.htm", 8) //转化为htm格式 doc.SvaeAs("E:/1.fpt",17) doc.Close() word.Quit() if __name__ == '__main__': saveHtm()
Method 3: At the same time, the Office API directly displays the word document on the web page
<iframe src="http://view.officeapps.live.com/op/view.aspx?src=公网上能访问的word文档地址" ></iframe> 例 src="http://view.officeapps.live.com/op/view.aspxsrc=newteach.pbworks.com%2Ff%2Fele%2Bnewsletter.docx"
Method 4: Through com component
需要所在宿主机,有offic的环境,Linxu下不能使用 (不推荐)
The above is the detailed content of How to convert uploaded word files to Html format with PHP. For more information, please follow other related articles on the PHP Chinese website!