简体   繁体   English

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

[英]Opening Word document in read mode using php?

I want to read a Word document in a browser using PHP. 我想使用PHP在浏览器中阅读Word文档。 I have been trying for more than two hours, but I cant get it to work. 我已经尝试了两个多小时,但我无法让它工作。 Can someone help me do this? 有人可以帮我这么做吗?

As your not too detailed in your question on your specific requirements or server setup, this will get you started & also answers the question. 由于您对特定要求或服务器设置的问题不太详细,这将使您开始并回答问题。

<?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)
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM