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

发布于 2024-07-07 04:52:07 字数 97 浏览 8 评论 0原文

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

I was trying to test code using com class to display Word files but I cannot seem to get the answer and still searching. I get errors and sometimes, programs do not display anything at all. Please give me some ideas. I'm working with PHP 4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青衫儰鉨ミ守葔 2024-07-14 04:52:07

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

可能还有很多其他的。

尽管我过去见过代码实际上可以在不使用自动化的情况下直接读取 Word 文档,但我不推荐它,因为它很容易被新版本或奇怪的文件格式破坏。

If the site is hosted on a Windows machine with Word you may be able to use a COM extension to PHP that will give you access to Word documents. Using the automation methods exposed by Word's Automation model, you could probably do something like export a word document to HTML and then render that HTML to some frame/div on your page. I haven't looked at the code or tried it, but someone has created a word/php class here:
http://www.phpclasses.org/browse/package/3553.html

There are probably many others.

Although I have seen code in the past that will actually read a Word document directly without the use of Automation, I wouldn't recommend it as it could be easily broken by new versions or oddities in file format.

九局 2024-07-14 04:52:07

您的意思是您想在浏览器中激活单词插件吗? 尝试 < /a> 带有正确 mime 类型的标记。

Do you mean you want to have the word plugin activated in the browser? Try the <object> tag with the correct mime type.

笑脸一如从前 2024-07-14 04:52:07
<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>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文