FW: Com++ Word AND PHP?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: George Pitcher [mailto:george.pitcher@xxxxxxxxxxx] 
Sent: Monday, October 08, 2007 3:02 PM
To: Gustav Wiberg
Subject: RE:  Com++ Word AND PHP?

Gustav,

> I'm trying to run Word and save as a document in PHP. I have tested...
>
> <?php
> $word = new COM("word.application");
> //To see the version of Microsoft Word, just use $word->Version
> echo "I'm using MS Word {$word->Version}";
> //It's better to keep Word invisible
> $word->Visible = 0;
> //Creating new document
> $word->Documents->Add();
> //Setting 2 inches margin on the both sides
> $word->Selection->PageSetup->LeftMargin = '2"';
> $word->Selection->PageSetup->RightMargin = '2"';
> //Setup the font
> $word->Selection->Font->Name = 'Verdana';
> $word->Selection->Font->Size = 8;
> //Write some text
> $word->Selection->TypeText("Hello, universe!");
> //Save the document as DOC file
> $word->Documents[0]->SaveAs("C:\hello2.doc");
> // or use: $word->Documents[1]->SaveAs("C:htdocshello2.rtf",6);
> to save as RTF file
> // or use: $word->Documents[1]->SaveAs("C:htdocshello2.htm",8);
> to save as HTML file
> //And of course, quit Word
> $word->quit();
> //$word->Release();
> $word = null;
> //Give the user a download link
> echo '<a href="hello2.doc">Download file as .doc</a>';
> ?>
>
>
>
> On the line
> $word -> $word->Documents[0]->SaveAs("C:\hello2.doc");
>
> I get the error:
> Fatal error: Uncaught exception 'com_exception' with message
> '<b>Source:</b> Microsoft Word<br/><b>Description:</b> Den
> begärda medlemmen i en av samlingarna finns inte.' in
> C:\www\testword2.php:18 Stack trace: #0 C:\www\testword2.php(18):
> unknown() #1 {main} thrown in C:\www\testword2.php on line 18
>
> I have setup a locally account which logs in to IIS and have set
> the rights in ComponentServices/Microsoft word.
> The word-application seems to initiate but the save-as doesn't
> seem to work.
>
> I'm using IIS on a windows XP. (I want to test locally before
> using on a production server)
>
> What am I doing wrong?
>

I do this on my WinNT server - in fact its the only thing left stopping me
from moving to Linux!

My save line looks like:

$word->Documents[1]->SaveAs($fp2);

$fp2 is the path and name of the file.
The only difference being the '[1]' compared to your '[0]'.

Hope this helps.

Hi

No, I'm sorry it didn't help to change to [1]):

/Gustav



No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.14.4/1056 - Release Date: 2007-10-07 18:12
 


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.14.4/1056 - Release Date: 2007-10-07 18:12
 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux