VBScript - TO - PHP... Open-Method-COM+

VBScript - TO - PHP... Open-Method-COM+

am 09.10.2007 10:32:00 von Gustav Wiberg

Hi again
=20
I don't know If I figure out exactly how to "convert" VB-application to PHP=
-code...
I'm using the reference:http://msdn2.microsoft.com/en-us/library/aa220317( o=
ffice.11).aspx
(Because I'm using Word 2003 as test-application)

=20
And viewing example: "As it applies to Document-object"


=20


And I think THIS would be done like this in PHP ?=20
(I get the following error: I'm using MS Word 11.0
Fatal error: Uncaught exception 'com_exception' with message 'Unable to loo=
kup `Open': Okänt namn. ' in C:\www\testword2.php:22 Stack trace: #0 C:\w=
ww\testword2.php(22): unknown() #1 {main} thrown in C:\www\testword2.php on=
line 22)Okänt namn =3D unkown name



(The test.doc exists)=20
$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 1;
//Creating new document
$word->Documents->Add();
=20
=20

//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 16;
=20
$doc =3D $word->Selection->Document;
$docName =3D "c:\\www\\test.doc";
$doc->Open($docName);
=20
=20
=20
?>


What am I doing wrong/thinking wrong? =20


Best regards
/Gustav Wiberg


No virus found in this outgoing message.
Checked by AVG Free Edition.=20
Version: 7.5.488 / Virus Database: 269.14.5/1058 - Release Date: 2007-10-08=
16:54
=20

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

Re: VBScript - TO - PHP... Open-Method-COM+

am 09.10.2007 11:12:39 von Niel Archer

Hi

First off, let me say I don't use Word, don't even have it installed
on my computers, so I can't test any of this.

You seem to be doing unnecessary stuff to open one document (adding a
new one that's not used after). Have you looked at PHP's online
documentation for .COM (http://www.php.net/manual/en/ref.com.php). It
has some excellent comments and examples from other users, one of which
I reproduce below.

an easy way to convert your file from .doc to .html

// starting word
$word =3D new COM("word.application") or die("Unable to instanciate Word");

// if you want see the World interface the value must be '1' else '0'
$word->Visible =3D 1;

//doc file location
$word->Documents->Open("E:\\first.doc");

//html file location '8' mean HTML format
$word->Documents[1]->SaveAs("E:\\test_doc.html",8);

//closing word
$word->Quit();

//free the object from the memory
$word->Release();
$word =3D null;


> Hi again
> =20
> I don't know If I figure out exactly how to "convert" VB-application to P=
HP-code...
> I'm using the reference:http://msdn2.microsoft.com/en-us/library/aa220317=
(office.11).aspx
> (Because I'm using Word 2003 as test-application)
>=20
> =20
> And viewing example: "As it applies to Document-object"
>=20
>=20
> =20
>=20
>=20
> And I think THIS would be done like this in PHP ?=20
> (I get the following error: I'm using MS Word 11.0
> Fatal error: Uncaught exception 'com_exception' with message 'Unable to l=
ookup `Open': Okänt namn. ' in C:\www\testword2.php:22 Stack trace: #0 C:=
\www\testword2.php(22): unknown() #1 {main} thrown in C:\www\testword2.php =
on line 22)Okänt namn =3D unkown name
>=20
>=20
>=20
> (The test.doc exists)=20
> > $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 1;
> //Creating new document
> $word->Documents->Add();
> =20
> =20
>=20
> //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 16;
> =20
> $doc =3D $word->Selection->Document;
> $docName =3D "c:\\www\\test.doc";
> $doc->Open($docName);
> =20

--
Niel Archer

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

RE: VBScript - TO - PHP... Open-Method-COM+

am 09.10.2007 11:18:00 von Gustav Wiberg

Hi!

Aha. Ok. I used
$word->Selection->Documents->Open("c:\\www\\test.doc");
instead of
$word->Documents->Open("c:\\www\\test.doc");

Thanx!

/Gustav


-----Original Message-----
From: Niel Archer [mailto:not@chance.now]=20
Sent: Tuesday, October 09, 2007 11:13 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] VBScript - TO - PHP... Open-Method-COM+

Hi

First off, let me say I don't use Word, don't even have it installed
on my computers, so I can't test any of this.

You seem to be doing unnecessary stuff to open one document (adding a
new one that's not used after). Have you looked at PHP's online
documentation for .COM (http://www.php.net/manual/en/ref.com.php). It
has some excellent comments and examples from other users, one of which
I reproduce below.

an easy way to convert your file from .doc to .html

// starting word
$word =3D new COM("word.application") or die("Unable to instanciate Word");

// if you want see the World interface the value must be '1' else '0'
$word->Visible =3D 1;

//doc file location
$word->Documents->Open("E:\\first.doc");

//html file location '8' mean HTML format
$word->Documents[1]->SaveAs("E:\\test_doc.html",8);

//closing word
$word->Quit();

//free the object from the memory
$word->Release();
$word =3D null;


> Hi again
> =20
> I don't know If I figure out exactly how to "convert" VB-application to P=
HP-code...
> I'm using the reference:http://msdn2.microsoft.com/en-us/library/aa220317=
(office.11).aspx
> (Because I'm using Word 2003 as test-application)
>=20
> =20
> And viewing example: "As it applies to Document-object"
>=20
>=20
> =20
>=20
>=20
> And I think THIS would be done like this in PHP ?=20
> (I get the following error: I'm using MS Word 11.0
> Fatal error: Uncaught exception 'com_exception' with message 'Unable to l=
ookup `Open': Okänt namn. ' in C:\www\testword2.php:22 Stack trace: #0 C:=
\www\testword2.php(22): unknown() #1 {main} thrown in C:\www\testword2.php =
on line 22)Okänt namn =3D unkown name
>=20
>=20
>=20
> (The test.doc exists)=20
> > $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 1;
> //Creating new document
> $word->Documents->Add();
> =20
> =20
>=20
> //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 16;
> =20
> $doc =3D $word->Selection->Document;
> $docName =3D "c:\\www\\test.doc";
> $doc->Open($docName);
> =20

--
Niel Archer

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


No virus found in this outgoing message.
Checked by AVG Free Edition.=20
Version: 7.5.488 / Virus Database: 269.14.5/1058 - Release Date: 2007-10-08=
16:54
=20

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