Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2007, 06:26 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP & COM MS Office

Dear all

i tried this fine artical which guide hot to write php code to create ms office file using COM.

http://web.informbank.com/articles/t...-documents.htm

the problem that all the examples in this guide worked fine except the ms word example i am getting the following error:

this is the output:
I'm using MS Word 11.0
Fatal error: Call to a member function TypeText() on a non-object in C:\Inetpub\temp\index.php on line ...

$word->Selection->TypeText("Hello, universe!"); // error is here !

please help i tried everything...

note: i am using windows server 2003 sbs and php 5 and office 2003

************************

ok i have another code which also give error and did know how to solve it

this the error :

Loaded Word, version 11.0
Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: Command failed' in C:\Inetpub\temp\index.php:... Stack trace: #0 C:\Inetpub\temp\index.php(...): variant->Open('C:/inetpub/temp...') #1 {main} thrown in C:\Inetpub\temp\index.php on line ...

Code:
<?php
 //1. Instanciate Word
$word = new COM("word.application") or die("Unable to instantiate Word");
print "Loaded Word, version {$word->Version}\n";
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = "C:/Inetpub/temp/reminder.doc";
//3. open the template document
$word->Documents->Open($template_file);
//4. get the current date MM/DD/YYYY
$current_date = date("m/d/Y");
//5. get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname = "TODAYDATE";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
//6. now substitute the bookmark with actual value
$range->Text = $current_date;
//7. save the template as a new document (c:/reminder_new.doc)
$new_file = "C:/Inetpub/temp/reminder_new.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
$word->Release();
$word = null;

?>
 
Old March 20th, 2007, 07:09 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

helloo help ...!!!

 
Old March 26th, 2007, 03:36 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

again helloo help ...!!!

 
Old April 26th, 2007, 02:31 PM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to phoenixatareva
Default

Hello, I really would like to help you
seem that I have a similar problem!
it's on the
Code:
$word->Documents[1]->SaveAs
function

System answers that argument n°1 can be passed as reference.

I'm using PHP 5.2.1, it's supposed to implement this functionnality.

Good luck :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Script Editor in MS Office 2007 sektor VBScript 1 June 28th, 2010 04:44 PM
different ways of interfacing with MS Office chandler7272 C# 3 July 21st, 2006 03:52 PM
visual studio for ms office dartcoach Access 2 June 17th, 2005 02:38 PM
uploading ms excel without office on server vauneen Classic ASP Components 0 April 13th, 2005 09:16 AM
PHP & MS Active Directory spraveens PHP Databases 1 April 30th, 2004 07:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.