php word轉(zhuǎn)化為html的實現(xiàn)方法:首先通過composer安裝phpoffice;然后查看vendor文件夾;最后通過“$xmlwriter ->save('./ceshi.htm');”方式將word文件轉(zhuǎn)化為html格式。
推薦:《php視頻教程》
方法一: 通過phpoffice(推薦)
1: composer require phpoffice/phpword /* 通過composer安裝 phpoffice 需要科學上網(wǎng) 或者用中國鏡像: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 */方法二:通過python
from win32com import client as wcimport sysdef 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) //轉(zhuǎn)化為htm格式 doc.svaeas("e:/1.fpt",17) doc.close() word.quit()if __name__ == '__main__': savehtm()方法三:同時offic api直接在網(wǎng)頁顯示word文檔
<iframe src="http://view.officeapps.live.com/op/view.aspx?src=公網(wǎng)上能訪問的word文檔地址" ></iframe>例src="http://view.officeapps.live.com/op/view.aspxsrc=newteach.pbworks.com/f/ele+newsletter.docx" 方法四:通過com組件
需要所在宿主機,有offic的環(huán)境,linxu下不能使用(不推薦)