我想使用 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)
?>
关于php - 使用 php 以读取模式打开 Word 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144023/