【问题标题】:How can I display Word documents in a textarea using PHP?如何使用 PHP 在文本区域中显示 Word 文档?
【发布时间】:2008-10-20 10:06:14
【问题描述】:

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

【问题讨论】:

    标签: php ms-word


    【解决方案1】:

    如果站点托管在装有 Word 的 Windows 计算机上,您可以使用 PHP 的 COM 扩展来访问 Word 文档。使用 Word 的自动化模型公开的自动化方法,您可能会执行一些操作,例如将 word 文档导出到 HTML,然后将该 HTML 呈现到页面上的某个框架/div。我没有看代码也没有尝试过,但是有人在这里创建了一个word/php类:
    http://www.phpclasses.org/browse/package/3553.html

    可能还有很多其他的。

    虽然我在过去看到过无需使用自动化就可以直接读取 Word 文档的代码,但我不推荐使用它,因为它很容易被新版本或文件格式的怪异所破坏。

    【讨论】:

    • 我已经尝试过这段代码,但我得到了路径无效之类的错误。但是当我有文件所在的路径时。我现在使用的php版本会不会和它有关?
    • 我为团队拿了一个,浏览了可怕的,可怕的网站phpclasses,注册,结果它也依赖于COM。
    • +1 用于 phpclasses 评论。我的意思是,真的。添加一些字幕和闪烁的文字,又是 1995 年。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 请尝试理解代码是实现cory并将doc文件打开到文本区域
      猜你喜欢
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多