Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b>com question</b>

Status
Not open for further replies.

dingleberry

Programmer
Joined
Dec 13, 2002
Messages
143
Location
US
Hi. I've been trying to figure out how to create a word document from php. I've been combing the internet and came across this snippit.
<?
// create a reference to a new COM component (Word)
$word = new COM(&quot;word.application&quot;) or die(&quot;Can't start Word!&quot;);


// print the version of Word that's now in use
echo &quot;Loading Word, v. {$word->Version}<br>&quot;;

// set the visibility of the application to 0 (false)
// to open the application in the forefront, use 1 (true)
$word->Visible = 1;

// create a new document in Word
$word->Documents->Add();

// add text to the new document
$word->Selection->TypeText(&quot;Testing 1-2-3...&quot;);

//save the document in the Windows temp directory
$word->Documents[1]->SaveAs(&quot;c:/comtest.doc&quot;);

// close the connection to the COM component
$word->Quit();

// print another message to the screen
echo &quot;Check for the file...&quot;;
?>

when I execute it I get this echod to my browser.

Loading Word, v. 8.0

Warning: (null)(): Invoke() failed: Type mismatch. Argument: 2 in c:\program files\apache group\apache\htdocs\test.php on line 17

Warning: (null)(): Invoke() failed: Type mismatch. Argument: 2 in c:\program files\apache group\apache\htdocs\test.php on line 20
Check for the file...

Any ideas on why I'm getting those errors?

Thanks,
Dan
 
what OS are you running? is Word installed on the server? Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Wow! Thanks for the immediate response. Word is installed on my server and I am running win32 server but I'm doing so with Apache because I hate iis. My OS on this box is win2000 pro sp 3. Very small application with very limited users.

Thanks,
Dan

Sleepnir, the lines referenced in my errors are lines 17
$word->Selection->TypeText(&quot;Testing 1-2-3...&quot;);

and 20
$word->Documents[1]->SaveAs(&quot;c:/comtest.doc&quot;);

Thanks,
Dan
 
Hi,

I'm having exact the same problem. So i was wondering if you already know what the solution is.

 
I was using Word 97. There were some com bugs in place. I patched it and it helped but didn't work exactly. What I ended up using was a class called

wd97template.class.php

I cannot find it anymore unfortunately, but I think it's available online. It was a life saver for me because it did exactly what I needed it to do which was replace text tags in a .dot or .doc file with results from a mysql query.

 
Thanks for your quick respons.

I'm also using Word 97, so that could be the problem. I'm also using PHP 4.1.1. Could it be hat I also need an upgrade of my PHP-version?

The word-application that is opened, is running from my server, so Word opens on my server. Is it possible to open the Word-application of the client so that he/she can edit the document?

 
I strongly recommend that you upgrade your PHP version. There are lots of bug fixes and security enhancements between 4.1.1 and 4.3.4.


It's probably possible to open Word on the client. However, since to do so you would have to use client-side scripting and PHP is server-side scripting, you're not asking a PHP question.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I agree with Sleipnir214's response. You would want to look at javascript or a windows based equivalent to open client side applications. If you do figure it out, I'd love to hear how you did it. Perhaps even get my paws on a sample of your source. It's something I've toyed around with trying to figure out for a while but have never really dedicated myself to doing. Good luck!

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top