您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“php將word轉換為html格式的方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“php將word轉換為html格式的方法”吧!
PHP將上傳word文件,轉化為Html格式,(多種轉換方式)
1: composer require phpoffice/phpword
/* 通過composer安裝 PHPOffice
需要科學上網(wǎng)
或者用中國鏡像:https://www.phpcomposer.com/
*/
2: 安裝成功可看到 vendor文件夾
3: 使用方法 :
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
*/
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()
src="http://view.officeapps.live.com/op/view.aspx?src=公網(wǎng)上能訪問的word文檔地址" >
例
src="http://view.officeapps.live.com/op/view.aspxsrc=newteach.pbworks.com%2Ff%2Fele%2Bnewsletter.docx"
需要所在宿主機,有offic的環(huán)境,Linxu下不能使用
實例擴展:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>接收上傳文件</title> <?php $conn = @new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("person.mdb"); $conn->Open($connstr); $uploaddir = 'uploads/'; if(!is_dir($uploaddir)){ mkdir($uploaddir); } $filename =$_FILES['filename']['name']; $filename =substr($_FILES['filename']["name"],0,strpos($_FILES['filename']["name"],".")); echo $filename; echo "<br>"; $uploadfile = $uploaddir.$filename.substr($_FILES['filename']["name"],strpos($_FILES['filename']["name"],".")); //目錄名.文件名.后綴名 echo $uploadfile; echo "<br>"; $temploadfile = $_FILES['filename']['tmp_name']; echo $temploadfile; echo "<br>"; move_uploaded_file($temploadfile , $uploadfile); //移動文件 $path = $_SERVER['SCRIPT_FILENAME']; $filepath = $_SERVER["PHP_SELF"]; $path = substr($path,0,strpos($path,$filepath)); echo $path; echo "<br>"; echo $filepath; $htmlpath = $path."/shiyan4/".$uploadfile; echo "<br>"; echo $htmlpath; word2html($htmlpath); //$query =@mysql_query( "Insert into $username(fname,file)values('$filename','$uploadfile')")or die("error"); ?> <?php //http://tieba.baidu.com/f?kz=13975389 function word2html($wfilepath) { $word=new COM("Word.Application") or die("無法打開 MS Word"); $word->visible = 1 ; $word->Documents->Open($wfilepath)or die("無法打開這個文件"); $htmlpath=substr($wfilepath,0,-4); $word->ActiveDocument->SaveAs($htmlpath,8); $word->quit(0); } print( "Word轉html完成!" ); ?> </head> <body> </body> </html>
到此,相信大家對“php將word轉換為html格式的方法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。