Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php以读取模式打开Word文档?_Php - Fatal编程技术网

使用php以读取模式打开Word文档?

使用php以读取模式打开Word文档?,php,Php,我想用PHP在浏览器中阅读Word文档。 我已经试了两个多小时了,但还是没能成功。 有人能帮我做这件事吗?由于您的问题中没有太详细的说明您的具体要求或服务器设置,这将帮助您开始并回答问题 <?php $DocumentPath="C:/xampp/htdocs/test.doc"; //Create an instance of the Word application $word = new COM("word.application") or die("Unable to instan

我想用PHP在浏览器中阅读Word文档。 我已经试了两个多小时了,但还是没能成功。
有人能帮我做这件事吗?

由于您的问题中没有太详细的说明您的具体要求或服务器设置,这将帮助您开始并回答问题

<?php
$DocumentPath="C:/xampp/htdocs/test.doc";
//Create an instance of the Word application
$word = new COM("word.application") or die("Unable to instantiate application object");
//Creating an instance of the Word Document object
$wordDocument = new COM("word.document") or die("Unable to instantiate document object");
$word->Visible = 0;
//Open up an empty document
$wordDocument = $word->Documents->Open($DocumentPath);

//Create the filename for the HTML version
$HTMLPath = substr_replace($DocumentPath, 'html', -3, 3);
//Save the document as HTML
$wordDocument->SaveAs($HTMLPath, 3);
// clean up
$wordDocument = null;
$word->Quit();
$word = null;
// read the newly-created document
readfile($HTMLPath);
//delete the file
unlink($HTMLPath)
?>


word文档在您的服务器上是否正确?这是*nix还是Windows环境?