2

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.

Todd Main
  • 28,951
  • 11
  • 82
  • 146

3 Answers3

2

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.

Karim
  • 18,347
  • 13
  • 61
  • 70
  • i've tried this code already and i get error like path is not valid. but when i've the path to where the file is located. could the php version i am using right now has something to do with it? –  Oct 20 '08 at 11:15
  • 1
    I took one for the team and went through the horrible, horrible website phpclasses, registered, and it turns out that it relies on COM as well. – cgp Oct 29 '10 at 05:58
  • +1 for phpclasses comment. i mean, really. add some marquees and flashing text and it's 1995 again. – Karim Oct 29 '10 at 11:23
0

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

Paul de Vrieze
  • 4,888
  • 1
  • 24
  • 29
0

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