FW: Com++ Word AND PHP?
am 08.10.2007 15:18:00 von Gustav Wiberg-----Original Message-----
From: George Pitcher [mailto:george.pitcher@ingenta.com]=20
Sent: Monday, October 08, 2007 3:02 PM
To: Gustav Wiberg
Subject: RE: [PHP-WIN] Com++ Word AND PHP?
Gustav,
> I'm trying to run Word and save as a document in PHP. I have tested...
>
>
> $word =3D 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 =3D 0;
> //Creating new document
> $word->Documents->Add();
> //Setting 2 inches margin on the both sides
> $word->Selection->PageSetup->LeftMargin =3D '2"';
> $word->Selection->PageSetup->RightMargin =3D '2"';
> //Setup the font
> $word->Selection->Font->Name =3D 'Verdana';
> $word->Selection->Font->Size =3D 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 =3D null;
> //Give the user a download link
> echo '';
> ?>
>
>
>
> On the line
> $word -> $word->Documents[0]->SaveAs("C:\hello2.doc");
>
> I get the error:
> Fatal error: Uncaught exception 'com_exception' with message
> 'Source: Microsoft Word
Description: 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.=20
Version: 7.5.488 / Virus Database: 269.14.4/1056 - Release Date: 2007-10-07=
18:12
=20
No virus found in this outgoing message.
Checked by AVG Free Edition.=20
Version: 7.5.488 / Virus Database: 269.14.4/1056 - Release Date: 2007-10-07=
18:12
=20
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php