如何使用PHP在文本区域中显示Word文档


How can I display Word documents in a textarea using PHP?

我试图使用com类来测试代码以显示Word文件,但似乎无法得到答案,仍在搜索。我会遇到错误,有时程序根本不显示任何内容。请给我一些想法。我使用的是PHP 4。

如果网站托管在装有Word的Windows机器上,您可以使用PHP的COM扩展,从而访问Word文档。使用Word的automation模型公开的自动化方法,您可能会做一些事情,比如将Word文档导出为HTML,然后将该HTML呈现为页面上的某个frame/div。我还没有看过代码或尝试过它,但有人在这里创建了一个word.php类:
http://www.phpclasses.org/browse/package/3553.html

可能还有很多其他的。

尽管我以前见过不使用Automation就可以直接读取Word文档的代码,但我不建议使用它,因为它很容易被新版本或文件格式的奇怪之处破坏。

你是说你想在浏览器中激活插件这个词吗?请尝试使用正确的mime类型的<object>标记。

<head><title>snook.ca load document</title>
<script language="JavaScript">
<!--//
function loadworddoc(){
    // creates the word object
    var doc = new ActiveXObject("Word.Application"); 
    // doesn't display Word window
    doc.Visible=false; 
    // specify path to document
    doc.Documents.Open(document.all.hello.value); 

   //copy the content from my word document and throw it into my variable
   var txt;
   txt = doc.Documents(document.all.hello.value).Content;
   //document.all.myarea.value = txt;
   document.all.tbContentElement.DOM.body.innerHTML = txt;
   // quit word (very important or you'll quickly chew up memory!)
   doc.quit(0); 
   }
   //-->
   </script>
</head>
<body>
   <p><input type=button onClick="loadworddoc();" value="Load">
   <p><input type=file name=hello>
   <p><textarea name=myarea cols=50 rows=5>nothing here yet</textarea>
   <object ID="tbContentElement" CLASS="tbContentElement" 
     CLASSID="clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A" VIEWASTEXT
     width="450" height="300">
     <param name=Scrollbars value=true></object>
</body>