Excel OLE Automation using COM: file access problem
Excel OLE Automation using COM: file access problem
am 18.05.2009 08:14:59 von Samuel.Faubry
------_=_NextPart_001_01C9D77F.F8E2A879
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
=20
I am interfacing PHP and Excel to build a web-based reporting tool. I am =
running IIS6.0 with PHP 5.2.5 on Windows Server 2003, with Office 2003 =
installed.
=20
For testing purpose, I wrote a script that just connects to Excel, opens =
a workbook, saves it under another name and closes Excel:
=20
$if_path =3D 'C:\if_test.xls';
$of_path =3D 'C:\of_test.xls';
=20
echo date('H:i:s') . " Launch Excel application \n";
$excelApp =3D new COM("Excel.Application") or die("Cannot create an =
Excel object");
echo date('H:i:s') . " Loaded Excel, version {$excelApp->Version}\n";
=20
echo date('H:i:s') . " Open workbook at path $if_path\n";
$excelApp->Workbooks->Open($if_path, 2);
=20
echo date('H:i:s') . " Save changes to $of_path\n";
$excelApp->Workbooks[1]->SaveAs($of_path);
=20
echo date('H:i:s') . " Close Excel\n";
$excelApp->Quit();=20
=20
When I open the page in Internet Explorer, if I put =
"http://localhost/test.php", everything works fine, but if I put =
"http://my_server_name.domain.int/test.php", the script is blocked when =
trying to open the file, which means I can't access the script elsewhere =
than on the server.
=20
By "blocked", I mean no error is shown, but it doesn't react, and the =
excel.exe task keeps running and keeps the file locked.
=20
My guess is that Excel is run with different permissions in the second =
case, so it cannot access the file, but it might be completely something =
else...
=20
Does someone have any experience in that matter ?
=20
Thank you very much !
------_=_NextPart_001_01C9D77F.F8E2A879--
Re: Excel OLE Automation using COM: file access problem
am 18.05.2009 14:23:35 von Richard Quadling
2009/5/18 Faubry, Samuel :
> Hi,
>
> I am interfacing PHP and Excel to build a web-based reporting tool. I am =
running IIS6.0 with PHP 5.2.5 on Windows Server 2003, with Office 2003 inst=
alled.
>
> For testing purpose, I wrote a script that just connects to Excel, opens =
a workbook, saves it under another name and closes Excel:
>
> $if_path =3D 'C:\if_test.xls';
> $of_path =3D 'C:\of_test.xls';
>
> echo date('H:i:s') . " Launch Excel application \n";
> $excelApp =3D new COM("Excel.Application") or die("Cannot create an Excel=
object");
> echo date('H:i:s') . " Loaded Excel, version {$excelApp->Version}\n";
>
> echo date('H:i:s') . " Open workbook at path $if_path\n";
> $excelApp->Workbooks->Open($if_path, 2);
>
> echo date('H:i:s') . " Save changes to $of_path\n";
> $excelApp->Workbooks[1]->SaveAs($of_path);
>
> echo date('H:i:s') . " Close Excel\n";
> $excelApp->Quit();
>
> When I open the page in Internet Explorer, if I put "http://localhost/tes=
t.php", everything works fine, but if I put "http://my_server_name.domain.i=
nt/test.php", the script is blocked when trying to open the file, which mea=
ns I can't access the script elsewhere than on the server.
>
> By "blocked", I mean no error is shown, but it doesn't react, and the exc=
el.exe task keeps running and keeps the file locked.
>
> My guess is that Excel is run with different permissions in the second ca=
se, so it cannot access the file, but it might be completely something else=
....
>
> Does someone have any experience in that matter ?
>
> Thank you very much !
>
>
If it is permissions, TEMPORARILY, allow IIS to interact with the
desktop. Hopefully you can RDP to the server as the console and see
what error message pops up (if any).
As PHP and excel run on the server, you will need to see the server
for any errors that can be displayed in this regard.
I don't think you'll be able to do this on server 2008 as the
"console" is no longer displayed (session 0 is purely for internal use
only - services and the like - and no display is allowed).
--=20
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
"Standing on the shoulders of some very clever giants!"
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Excel OLE Automation using COM: file access problem
am 19.05.2009 04:55:16 von Samuel.Faubry
> From: Richard Quadling
> 2009/5/18 Faubry, Samuel :
> > Hi,
> >
> > I am interfacing PHP and Excel to build a web-based
> reporting tool. I am running IIS6.0 with PHP 5.2.5 on Windows
> Server 2003, with Office 2003 installed.
> >
> > For testing purpose, I wrote a script that just connects to
> Excel, opens a workbook, saves it under another name and closes Excel:
> >
> > $if_path =3D 'C:\if_test.xls';
> > $of_path =3D 'C:\of_test.xls';
> >
> > echo date('H:i:s') . " Launch Excel application \n";
> > $excelApp =3D new COM("Excel.Application") or die("Cannot
> create an Excel object");
> > echo date('H:i:s') . " Loaded Excel, version
> {$excelApp->Version}\n";
> >
> > echo date('H:i:s') . " Open workbook at path $if_path\n";
> > $excelApp->Workbooks->Open($if_path, 2);
> >
> > echo date('H:i:s') . " Save changes to $of_path\n";
> > $excelApp->Workbooks[1]->SaveAs($of_path);
> >
> > echo date('H:i:s') . " Close Excel\n";
> > $excelApp->Quit();
> >
> > When I open the page in Internet Explorer, if I put
> "http://localhost/test.php", everything works fine, but if I
> put "http://my_server_name.domain.int/test.php", the script
> is blocked when trying to open the file, which means I can't
> access the script elsewhere than on the server.
> >
> > By "blocked", I mean no error is shown, but it doesn't
> react, and the excel.exe task keeps running and keeps the file locked.
> >
> > My guess is that Excel is run with different permissions in
> the second case, so it cannot access the file, but it might
> be completely something else...
> >
> > Does someone have any experience in that matter ?
> >
> > Thank you very much !
> >
> >
>
> If it is permissions, TEMPORARILY, allow IIS to interact with the
> desktop. Hopefully you can RDP to the server as the console and see
> what error message pops up (if any).
>
> As PHP and excel run on the server, you will need to see the server
> for any errors that can be displayed in this regard.
>
> I don't think you'll be able to do this on server 2008 as the
> "console" is no longer displayed (session 0 is purely for internal use
> only - services and the like - and no display is allowed).
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer :
> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
> "Standing on the shoulders of some very clever giants!"
>=20
Hi, thanks for your reply, Richard.
I RDP'd to the server console, but no error pops up. I allowed IIS to
interact with the desktop, but I didn't change anything.
I might have found the problem: the file I am trying to open has
external links. With a "normal" file it works fine whatever way I run
the script.
That's why I used the second argument (UpdateLinks) in the Open call
documented here (2 means "Never update links for this workbook on
opening"):
http://msdn.microsoft.com/en-us/library/microsoft.office.int erop.excel.w
orkbooks.open(office.11).aspx
Apparently, the argument I passed (2 of PHP type integer) is invalid.
Let me explain why I think so:
In the following, I am running everything from
http://localhost/test.php, which allows user interaction.
If I put $excelApp->Visible =3D 0 and use 2 as the UpdateLinks argument =
to
Open, everything runs fine without any interaction with the user.
If I put $excelApp->Visible =3D 1 and use 2 as the UpdateLinks argument =
to
Open, Excel shows up and tells me the links could not be updated, which
means it tried to update it, which is NOT the expected behaviour!=20
The values 1, 2 and 3 all give the same result, which is contradictory
with the documentation (1 is "ask", 2 is "do not update" and 3 is "do
update").=20
If I put 0, Excel shows up and closes without any interaction, but 0 is
not an authorised value according to the documentation.
Any other value crashes the script.
If I don't specify this argument, Excel shows up and asks me if I want
to update, which is the expected behaviour.
According to the documentation, this UpdateLinks argument is an Object,
maybe that's where the problem lies? If so, how can I create the object
to be passed as an argument to Open?
By the way, just out of curiosity, I tried to use the value 0 and run
the script from a client computer, but it is still blocked in the way
described above.
Thanks for your help !
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Excel OLE Automation using COM: file access problem
am 19.05.2009 10:28:02 von Richard Quadling
2009/5/19 Faubry, Samuel :
>> From: Richard Quadling
>> 2009/5/18 Faubry, Samuel :
>> > Hi,
>> >
>> > I am interfacing PHP and Excel to build a web-based
>> reporting tool. I am running IIS6.0 with PHP 5.2.5 on Windows
>> Server 2003, with Office 2003 installed.
>> >
>> > For testing purpose, I wrote a script that just connects to
>> Excel, opens a workbook, saves it under another name and closes Excel:
>> >
>> > $if_path = 'C:\if_test.xls';
>> > $of_path = 'C:\of_test.xls';
>> >
>> > echo date('H:i:s') . " Launch Excel application \n";
>> > $excelApp = new COM("Excel.Application") or die("Cannot
>> create an Excel object");
>> > echo date('H:i:s') . " Loaded Excel, version
>> {$excelApp->Version}\n";
>> >
>> > echo date('H:i:s') . " Open workbook at path $if_path\n";
>> > $excelApp->Workbooks->Open($if_path, 2);
>> >
>> > echo date('H:i:s') . " Save changes to $of_path\n";
>> > $excelApp->Workbooks[1]->SaveAs($of_path);
>> >
>> > echo date('H:i:s') . " Close Excel\n";
>> > $excelApp->Quit();
>> >
>> > When I open the page in Internet Explorer, if I put
>> "http://localhost/test.php", everything works fine, but if I
>> put "http://my_server_name.domain.int/test.php", the script
>> is blocked when trying to open the file, which means I can't
>> access the script elsewhere than on the server.
>> >
>> > By "blocked", I mean no error is shown, but it doesn't
>> react, and the excel.exe task keeps running and keeps the file locked.
>> >
>> > My guess is that Excel is run with different permissions in
>> the second case, so it cannot access the file, but it might
>> be completely something else...
>> >
>> > Does someone have any experience in that matter ?
>> >
>> > Thank you very much !
>> >
>> >
>>
>> If it is permissions, TEMPORARILY, allow IIS to interact with the
>> desktop. Hopefully you can RDP to the server as the console and see
>> what error message pops up (if any).
>>
>> As PHP and excel run on the server, you will need to see the server
>> for any errors that can be displayed in this regard.
>>
>> I don't think you'll be able to do this on server 2008 as the
>> "console" is no longer displayed (session 0 is purely for internal use
>> only - services and the like - and no display is allowed).
>>
>>
>> --
>> -----
>> Richard Quadling
>> Zend Certified Engineer :
>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>> "Standing on the shoulders of some very clever giants!"
>>
>
> Hi, thanks for your reply, Richard.
>
> I RDP'd to the server console, but no error pops up. I allowed IIS to
> interact with the desktop, but I didn't change anything.
>
> I might have found the problem: the file I am trying to open has
> external links. With a "normal" file it works fine whatever way I run
> the script.
>
> That's why I used the second argument (UpdateLinks) in the Open call
> documented here (2 means "Never update links for this workbook on
> opening"):
> http://msdn.microsoft.com/en-us/library/microsoft.office.int erop.excel.w
> orkbooks.open(office.11).aspx
>
> Apparently, the argument I passed (2 of PHP type integer) is invalid.
> Let me explain why I think so:
> In the following, I am running everything from
> http://localhost/test.php, which allows user interaction.
> If I put $excelApp->Visible = 0 and use 2 as the UpdateLinks argument to
> Open, everything runs fine without any interaction with the user.
> If I put $excelApp->Visible = 1 and use 2 as the UpdateLinks argument to
> Open, Excel shows up and tells me the links could not be updated, which
> means it tried to update it, which is NOT the expected behaviour!
> The values 1, 2 and 3 all give the same result, which is contradictory
> with the documentation (1 is "ask", 2 is "do not update" and 3 is "do
> update").
> If I put 0, Excel shows up and closes without any interaction, but 0 is
> not an authorised value according to the documentation.
> Any other value crashes the script.
> If I don't specify this argument, Excel shows up and asks me if I want
> to update, which is the expected behaviour.
>
> According to the documentation, this UpdateLinks argument is an Object,
> maybe that's where the problem lies? If so, how can I create the object
> to be passed as an argument to Open?
>
> By the way, just out of curiosity, I tried to use the value 0 and run
> the script from a client computer, but it is still blocked in the way
> described above.
>
> Thanks for your help !
>
A couple of things (taken as snippets from the online help and looking
through the type library) ...
AskToUpdateLinks Property
See AlsoApplies ToExampleSpecificsTrue if Microsoft Excel asks the
user to update links when opening files with links. False if links are
automatically updated with no dialog box. Read/write Boolean.
Example
This example sets Microsoft Excel to ask the user to update links
whenever a file that contains links is opened.
Application.AskToUpdateLinks = True
Do you have any macros as part of the file you open? If they present
dialogs, maybe they need to be suppressed also?
Application.DisplayAlerts = False
Workbooks("BOOK1.XLS").Close
Application.DisplayAlerts = True
Application.Workbooks.Open
UpdateLinks Optional Variant. Specifies the way links in the file
are updated. If this argument is omitted, the user is prompted to
specify how links will be updated. Otherwise, this argument is one of
the values listed in the following table.
Value Meaning
0 Doesn't update any references
1 Updates external references but not remote references
2 Updates remote references but not external references
3 Updates both remote and external references
Hmm..
Is it possible for you to run the PHP script from the command line on
the server using the same credentials used by IIS (or the app pool
used). I'm still not 100% uptodate with IIS+PHP security using
FastCGI. If you can get the script running, make sure you turn on
visibility within/for Excel so you can see what is happening.
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Excel OLE Automation using COM: file access problem
am 25.05.2009 09:08:26 von Samuel.Faubry
Hi Richard,
Sorry for not replying earlier, I've had other duties to take over.
Can you tell me from where you took the excerpts of documentation you
sent me in your last e-mail ? Because they are consistent with the
behaviour I observe, but not with the documentation on MSDN, so
apparently your documentation is more reliable.
Thanks,
Samuel
> -----Original Message-----
> From: Richard Quadling [mailto:rquadling@googlemail.com]=20
> Sent: Tuesday, May 19, 2009 5:28 PM
> To: Faubry, Samuel
> Cc: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Excel OLE Automation using COM: file=20
> access problem
>=20
> 2009/5/19 Faubry, Samuel :
> >> From: Richard Quadling
> >> 2009/5/18 Faubry, Samuel :
> >> > Hi,
> >> >
> >> > I am interfacing PHP and Excel to build a web-based
> >> reporting tool. I am running IIS6.0 with PHP 5.2.5 on=20
> Windows Server=20
> >> 2003, with Office 2003 installed.
> >> >
> >> > For testing purpose, I wrote a script that just connects to
> >> Excel, opens a workbook, saves it under another name and=20
> closes Excel:
> >> >
> >> > $if_path =3D 'C:\if_test.xls';
> >> > $of_path =3D 'C:\of_test.xls';
> >> >
> >> > echo date('H:i:s') . " Launch Excel application \n"; $excelApp =
=
> >> > new COM("Excel.Application") or die("Cannot
> >> create an Excel object");
> >> > echo date('H:i:s') . " Loaded Excel, version
> >> {$excelApp->Version}\n";
> >> >
> >> > echo date('H:i:s') . " Open workbook at path $if_path\n";=20
> >> > $excelApp->Workbooks->Open($if_path, 2);
> >> >
> >> > echo date('H:i:s') . " Save changes to $of_path\n";=20
> >> > $excelApp->Workbooks[1]->SaveAs($of_path);
> >> >
> >> > echo date('H:i:s') . " Close Excel\n"; $excelApp->Quit();
> >> >
> >> > When I open the page in Internet Explorer, if I put
> >> "http://localhost/test.php", everything works fine, but if I put=20
> >> "http://my_server_name.domain.int/test.php", the script is blocked=20
> >> when trying to open the file, which means I can't access=20
> the script=20
> >> elsewhere than on the server.
> >> >
> >> > By "blocked", I mean no error is shown, but it doesn't
> >> react, and the excel.exe task keeps running and keeps the=20
> file locked.
> >> >
> >> > My guess is that Excel is run with different permissions in
> >> the second case, so it cannot access the file, but it might be=20
> >> completely something else...
> >> >
> >> > Does someone have any experience in that matter ?
> >> >
> >> > Thank you very much !
> >> >
> >> >
> >>
> >> If it is permissions, TEMPORARILY, allow IIS to interact with the=20
> >> desktop. Hopefully you can RDP to the server as the=20
> console and see=20
> >> what error message pops up (if any).
> >>
> >> As PHP and excel run on the server, you will need to see=20
> the server=20
> >> for any errors that can be displayed in this regard.
> >>
> >> I don't think you'll be able to do this on server 2008 as the=20
> >> "console" is no longer displayed (session 0 is purely for internal=20
> >> use only - services and the like - and no display is allowed).
> >>
> >>
> >> --
> >> -----
> >> Richard Quadling
> >> Zend Certified Engineer :
> >> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
> >> "Standing on the shoulders of some very clever giants!"
> >>
> >
> > Hi, thanks for your reply, Richard.
> >
> > I RDP'd to the server console, but no error pops up. I=20
> allowed IIS to=20
> > interact with the desktop, but I didn't change anything.
> >
> > I might have found the problem: the file I am trying to open has=20
> > external links. With a "normal" file it works fine whatever=20
> way I run=20
> > the script.
> >
> > That's why I used the second argument (UpdateLinks) in the=20
> Open call=20
> > documented here (2 means "Never update links for this workbook on
> > opening"):
> >=20
> http://msdn.microsoft.com/en-us/library/microsoft.office.int erop.excel
> > .w
> > orkbooks.open(office.11).aspx
> >
> > Apparently, the argument I passed (2 of PHP type integer)=20
> is invalid.
> > Let me explain why I think so:
> > In the following, I am running everything from=20
> > http://localhost/test.php, which allows user interaction.
> > If I put $excelApp->Visible =3D 0 and use 2 as the=20
> UpdateLinks argument=20
> > to Open, everything runs fine without any interaction with the user.
> > If I put $excelApp->Visible =3D 1 and use 2 as the=20
> UpdateLinks argument=20
> > to Open, Excel shows up and tells me the links could not be=20
> updated,=20
> > which means it tried to update it, which is NOT the=20
> expected behaviour!
> > The values 1, 2 and 3 all give the same result, which is=20
> contradictory=20
> > with the documentation (1 is "ask", 2 is "do not update"=20
> and 3 is "do=20
> > update").
> > If I put 0, Excel shows up and closes without any=20
> interaction, but 0=20
> > is not an authorised value according to the documentation.
> > Any other value crashes the script.
> > If I don't specify this argument, Excel shows up and asks=20
> me if I want=20
> > to update, which is the expected behaviour.
> >
> > According to the documentation, this UpdateLinks argument is an=20
> > Object, maybe that's where the problem lies? If so, how can=20
> I create=20
> > the object to be passed as an argument to Open?
> >
> > By the way, just out of curiosity, I tried to use the value=20
> 0 and run=20
> > the script from a client computer, but it is still blocked=20
> in the way=20
> > described above.
> >
> > Thanks for your help !
> >
>=20
> A couple of things (taken as snippets from the online help=20
> and looking through the type library) ...
>=20
> AskToUpdateLinks Property
> See AlsoApplies ToExampleSpecificsTrue if Microsoft Excel=20
> asks the user to update links when opening files with links.=20
> False if links are automatically updated with no dialog box.=20
> Read/write Boolean.
>=20
> Example
> This example sets Microsoft Excel to ask the user to update=20
> links whenever a file that contains links is opened.
>=20
> Application.AskToUpdateLinks =3D True
> =09
>=20
>=20
> Do you have any macros as part of the file you open? If they=20
> present dialogs, maybe they need to be suppressed also?
>=20
> Application.DisplayAlerts =3D False
> Workbooks("BOOK1.XLS").Close
> Application.DisplayAlerts =3D True
>=20
>=20
>=20
> Application.Workbooks.Open
>=20
> UpdateLinks Optional Variant. Specifies the way links in the file
> are updated. If this argument is omitted, the user is=20
> prompted to specify how links will be updated. Otherwise,=20
> this argument is one of the values listed in the following table.
>=20
> Value Meaning
> 0 Doesn't update any references
> 1 Updates external references but not remote references
> 2 Updates remote references but not external references
> 3 Updates both remote and external references
>=20
>=20
> Hmm..
>=20
> Is it possible for you to run the PHP script from the command=20
> line on the server using the same credentials used by IIS (or=20
> the app pool used). I'm still not 100% uptodate with IIS+PHP=20
> security using FastCGI. If you can get the script running,=20
> make sure you turn on visibility within/for Excel so you can=20
> see what is happening.
>=20
> --
> -----
> Richard Quadling
> Zend Certified Engineer :=20
> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
> "Standing on the shoulders of some very clever giants!"
>=20
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Excel OLE Automation using COM: file access problem
am 27.05.2009 14:33:46 von Richard Quadling
2009/5/25 Faubry, Samuel :
> Hi Richard,
>
> Sorry for not replying earlier, I've had other duties to take over.
>
> Can you tell me from where you took the excerpts of documentation you
> sent me in your last e-mail ? Because they are consistent with the
> behaviour I observe, but not with the documentation on MSDN, so
> apparently your documentation is more reliable.
>
> Thanks,
>
> Samuel
>
>> -----Original Message-----
>> From: Richard Quadling [mailto:rquadling@googlemail.com]
>> Sent: Tuesday, May 19, 2009 5:28 PM
>> To: Faubry, Samuel
>> Cc: php-windows@lists.php.net
>> Subject: Re: [PHP-WIN] Excel OLE Automation using COM: file
>> access problem
>>
>> 2009/5/19 Faubry, Samuel :
>> >> From: Richard Quadling
>> >> 2009/5/18 Faubry, Samuel :
>> >> > Hi,
>> >> >
>> >> > I am interfacing PHP and Excel to build a web-based
>> >> reporting tool. I am running IIS6.0 with PHP 5.2.5 on
>> Windows Server
>> >> 2003, with Office 2003 installed.
>> >> >
>> >> > For testing purpose, I wrote a script that just connects to
>> >> Excel, opens a workbook, saves it under another name and
>> closes Excel:
>> >> >
>> >> > $if_path =3D 'C:\if_test.xls';
>> >> > $of_path =3D 'C:\of_test.xls';
>> >> >
>> >> > echo date('H:i:s') . " Launch Excel application \n"; $excelApp =3D
>> >> > new COM("Excel.Application") or die("Cannot
>> >> create an Excel object");
>> >> > echo date('H:i:s') . " Loaded Excel, version
>> >> {$excelApp->Version}\n";
>> >> >
>> >> > echo date('H:i:s') . " Open workbook at path $if_path\n";
>> >> > $excelApp->Workbooks->Open($if_path, 2);
>> >> >
>> >> > echo date('H:i:s') . " Save changes to $of_path\n";
>> >> > $excelApp->Workbooks[1]->SaveAs($of_path);
>> >> >
>> >> > echo date('H:i:s') . " Close Excel\n"; $excelApp->Quit();
>> >> >
>> >> > When I open the page in Internet Explorer, if I put
>> >> "http://localhost/test.php", everything works fine, but if I put
>> >> "http://my_server_name.domain.int/test.php", the script is blocked
>> >> when trying to open the file, which means I can't access
>> the script
>> >> elsewhere than on the server.
>> >> >
>> >> > By "blocked", I mean no error is shown, but it doesn't
>> >> react, and the excel.exe task keeps running and keeps the
>> file locked.
>> >> >
>> >> > My guess is that Excel is run with different permissions in
>> >> the second case, so it cannot access the file, but it might be
>> >> completely something else...
>> >> >
>> >> > Does someone have any experience in that matter ?
>> >> >
>> >> > Thank you very much !
>> >> >
>> >> >
>> >>
>> >> If it is permissions, TEMPORARILY, allow IIS to interact with the
>> >> desktop. Hopefully you can RDP to the server as the
>> console and see
>> >> what error message pops up (if any).
>> >>
>> >> As PHP and excel run on the server, you will need to see
>> the server
>> >> for any errors that can be displayed in this regard.
>> >>
>> >> I don't think you'll be able to do this on server 2008 as the
>> >> "console" is no longer displayed (session 0 is purely for internal
>> >> use only - services and the like - and no display is allowed).
>> >>
>> >>
>> >> --
>> >> -----
>> >> Richard Quadling
>> >> Zend Certified Engineer :
>> >> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
>> >> "Standing on the shoulders of some very clever giants!"
>> >>
>> >
>> > Hi, thanks for your reply, Richard.
>> >
>> > I RDP'd to the server console, but no error pops up. I
>> allowed IIS to
>> > interact with the desktop, but I didn't change anything.
>> >
>> > I might have found the problem: the file I am trying to open has
>> > external links. With a "normal" file it works fine whatever
>> way I run
>> > the script.
>> >
>> > That's why I used the second argument (UpdateLinks) in the
>> Open call
>> > documented here (2 means "Never update links for this workbook on
>> > opening"):
>> >
>> http://msdn.microsoft.com/en-us/library/microsoft.office.int erop.excel
>> > .w
>> > orkbooks.open(office.11).aspx
>> >
>> > Apparently, the argument I passed (2 of PHP type integer)
>> is invalid.
>> > Let me explain why I think so:
>> > In the following, I am running everything from
>> > http://localhost/test.php, which allows user interaction.
>> > If I put $excelApp->Visible =3D 0 and use 2 as the
>> UpdateLinks argument
>> > to Open, everything runs fine without any interaction with the user.
>> > If I put $excelApp->Visible =3D 1 and use 2 as the
>> UpdateLinks argument
>> > to Open, Excel shows up and tells me the links could not be
>> updated,
>> > which means it tried to update it, which is NOT the
>> expected behaviour!
>> > The values 1, 2 and 3 all give the same result, which is
>> contradictory
>> > with the documentation (1 is "ask", 2 is "do not update"
>> and 3 is "do
>> > update").
>> > If I put 0, Excel shows up and closes without any
>> interaction, but 0
>> > is not an authorised value according to the documentation.
>> > Any other value crashes the script.
>> > If I don't specify this argument, Excel shows up and asks
>> me if I want
>> > to update, which is the expected behaviour.
>> >
>> > According to the documentation, this UpdateLinks argument is an
>> > Object, maybe that's where the problem lies? If so, how can
>> I create
>> > the object to be passed as an argument to Open?
>> >
>> > By the way, just out of curiosity, I tried to use the value
>> 0 and run
>> > the script from a client computer, but it is still blocked
>> in the way
>> > described above.
>> >
>> > Thanks for your help !
>> >
>>
>> A couple of things (taken as snippets from the online help
>> and looking through the type library) ...
>>
>> AskToUpdateLinks Property
>> See AlsoApplies ToExampleSpecificsTrue if Microsoft Excel
>> asks the user to update links when opening files with links.
>> False if links are automatically updated with no dialog box.
>> Read/write Boolean.
>>
>> Example
>> This example sets Microsoft Excel to ask the user to update
>> links whenever a file that contains links is opened.
>>
>> Application.AskToUpdateLinks =3D True
>>
>>
>>
>> Do you have any macros as part of the file you open? If they
>> present dialogs, maybe they need to be suppressed also?
>>
>> Application.DisplayAlerts =3D False
>> Workbooks("BOOK1.XLS").Close
>> Application.DisplayAlerts =3D True
>>
>>
>>
>> Application.Workbooks.Open
>>
>> UpdateLinks  Optional Variant. Specifies the way links in the file
>> are updated. If this argument is omitted, the user is
>> prompted to specify how links will be updated. Otherwise,
>> this argument is one of the values listed in the following table.
>>
>> Value Meaning
>> 0 Doesn't update any references
>> 1 Updates external references but not remote references
>> 2 Updates remote references but not external references
>> 3 Updates both remote and external references
>>
>>
>> Hmm..
>>
>> Is it possible for you to run the PHP script from the command
>> line on the server using the same credentials used by IIS (or
>> the app pool used). I'm still not 100% uptodate with IIS+PHP
>> security using FastCGI. If you can get the script running,
>> make sure you turn on visibility within/for Excel so you can
>> see what is happening.
>>
>> --
>> -----
>> Richard Quadling
>> Zend Certified Engineer :
>> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
>> "Standing on the shoulders of some very clever giants!"
>>
>
I have a Type Library Viewer which allows me to see what the library
actually has to offer. Sometimes the docs are out of date.
A typelib is essentially a self-documenting library.
--=20
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
"Standing on the shoulders of some very clever giants!"
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Excel OLE Automation using COM: file access problem
am 27.05.2009 14:51:41 von Richard Quadling
http://www.jose.it-berater.org/
2009/5/27 Richard Quadling :
> 2009/5/25 Faubry, Samuel :
>> Hi Richard,
>>
>> Sorry for not replying earlier, I've had other duties to take over.
>>
>> Can you tell me from where you took the excerpts of documentation you
>> sent me in your last e-mail ? Because they are consistent with the
>> behaviour I observe, but not with the documentation on MSDN, so
>> apparently your documentation is more reliable.
>>
>> Thanks,
>>
>> Samuel
>>
>>> -----Original Message-----
>>> From: Richard Quadling [mailto:rquadling@googlemail.com]
>>> Sent: Tuesday, May 19, 2009 5:28 PM
>>> To: Faubry, Samuel
>>> Cc: php-windows@lists.php.net
>>> Subject: Re: [PHP-WIN] Excel OLE Automation using COM: file
>>> access problem
>>>
>>> 2009/5/19 Faubry, Samuel :
>>> >> From: Richard Quadling
>>> >> 2009/5/18 Faubry, Samuel :
>>> >> > Hi,
>>> >> >
>>> >> > I am interfacing PHP and Excel to build a web-based
>>> >> reporting tool. I am running IIS6.0 with PHP 5.2.5 on
>>> Windows Server
>>> >> 2003, with Office 2003 installed.
>>> >> >
>>> >> > For testing purpose, I wrote a script that just connects to
>>> >> Excel, opens a workbook, saves it under another name and
>>> closes Excel:
>>> >> >
>>> >> > $if_path =3D 'C:\if_test.xls';
>>> >> > $of_path =3D 'C:\of_test.xls';
>>> >> >
>>> >> > echo date('H:i:s') . " Launch Excel application \n"; $excelApp =3D
>>> >> > new COM("Excel.Application") or die("Cannot
>>> >> create an Excel object");
>>> >> > echo date('H:i:s') . " Loaded Excel, version
>>> >> {$excelApp->Version}\n";
>>> >> >
>>> >> > echo date('H:i:s') . " Open workbook at path $if_path\n";
>>> >> > $excelApp->Workbooks->Open($if_path, 2);
>>> >> >
>>> >> > echo date('H:i:s') . " Save changes to $of_path\n";
>>> >> > $excelApp->Workbooks[1]->SaveAs($of_path);
>>> >> >
>>> >> > echo date('H:i:s') . " Close Excel\n"; $excelApp->Quit();
>>> >> >
>>> >> > When I open the page in Internet Explorer, if I put
>>> >> "http://localhost/test.php", everything works fine, but if I put
>>> >> "http://my_server_name.domain.int/test.php", the script is blocked
>>> >> when trying to open the file, which means I can't access
>>> the script
>>> >> elsewhere than on the server.
>>> >> >
>>> >> > By "blocked", I mean no error is shown, but it doesn't
>>> >> react, and the excel.exe task keeps running and keeps the
>>> file locked.
>>> >> >
>>> >> > My guess is that Excel is run with different permissions in
>>> >> the second case, so it cannot access the file, but it might be
>>> >> completely something else...
>>> >> >
>>> >> > Does someone have any experience in that matter ?
>>> >> >
>>> >> > Thank you very much !
>>> >> >
>>> >> >
>>> >>
>>> >> If it is permissions, TEMPORARILY, allow IIS to interact with the
>>> >> desktop. Hopefully you can RDP to the server as the
>>> console and see
>>> >> what error message pops up (if any).
>>> >>
>>> >> As PHP and excel run on the server, you will need to see
>>> the server
>>> >> for any errors that can be displayed in this regard.
>>> >>
>>> >> I don't think you'll be able to do this on server 2008 as the
>>> >> "console" is no longer displayed (session 0 is purely for internal
>>> >> use only - services and the like - and no display is allowed).
>>> >>
>>> >>
>>> >> --
>>> >> -----
>>> >> Richard Quadling
>>> >> Zend Certified Engineer :
>>> >> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
>>> >> "Standing on the shoulders of some very clever giants!"
>>> >>
>>> >
>>> > Hi, thanks for your reply, Richard.
>>> >
>>> > I RDP'd to the server console, but no error pops up. I
>>> allowed IIS to
>>> > interact with the desktop, but I didn't change anything.
>>> >
>>> > I might have found the problem: the file I am trying to open has
>>> > external links. With a "normal" file it works fine whatever
>>> way I run
>>> > the script.
>>> >
>>> > That's why I used the second argument (UpdateLinks) in the
>>> Open call
>>> > documented here (2 means "Never update links for this workbook on
>>> > opening"):
>>> >
>>> http://msdn.microsoft.com/en-us/library/microsoft.office.int erop.excel
>>> > .w
>>> > orkbooks.open(office.11).aspx
>>> >
>>> > Apparently, the argument I passed (2 of PHP type integer)
>>> is invalid.
>>> > Let me explain why I think so:
>>> > In the following, I am running everything from
>>> > http://localhost/test.php, which allows user interaction.
>>> > If I put $excelApp->Visible =3D 0 and use 2 as the
>>> UpdateLinks argument
>>> > to Open, everything runs fine without any interaction with the user.
>>> > If I put $excelApp->Visible =3D 1 and use 2 as the
>>> UpdateLinks argument
>>> > to Open, Excel shows up and tells me the links could not be
>>> updated,
>>> > which means it tried to update it, which is NOT the
>>> expected behaviour!
>>> > The values 1, 2 and 3 all give the same result, which is
>>> contradictory
>>> > with the documentation (1 is "ask", 2 is "do not update"
>>> and 3 is "do
>>> > update").
>>> > If I put 0, Excel shows up and closes without any
>>> interaction, but 0
>>> > is not an authorised value according to the documentation.
>>> > Any other value crashes the script.
>>> > If I don't specify this argument, Excel shows up and asks
>>> me if I want
>>> > to update, which is the expected behaviour.
>>> >
>>> > According to the documentation, this UpdateLinks argument is an
>>> > Object, maybe that's where the problem lies? If so, how can
>>> I create
>>> > the object to be passed as an argument to Open?
>>> >
>>> > By the way, just out of curiosity, I tried to use the value
>>> 0 and run
>>> > the script from a client computer, but it is still blocked
>>> in the way
>>> > described above.
>>> >
>>> > Thanks for your help !
>>> >
>>>
>>> A couple of things (taken as snippets from the online help
>>> and looking through the type library) ...
>>>
>>> AskToUpdateLinks Property
>>> See AlsoApplies ToExampleSpecificsTrue if Microsoft Excel
>>> asks the user to update links when opening files with links.
>>> False if links are automatically updated with no dialog box.
>>> Read/write Boolean.
>>>
>>> Example
>>> This example sets Microsoft Excel to ask the user to update
>>> links whenever a file that contains links is opened.
>>>
>>> Application.AskToUpdateLinks =3D True
>>>
>>>
>>>
>>> Do you have any macros as part of the file you open? If they
>>> present dialogs, maybe they need to be suppressed also?
>>>
>>> Application.DisplayAlerts =3D False
>>> Workbooks("BOOK1.XLS").Close
>>> Application.DisplayAlerts =3D True
>>>
>>>
>>>
>>> Application.Workbooks.Open
>>>
>>> UpdateLinks  Optional Variant. Specifies the way links in the fil=
e
>>> are updated. If this argument is omitted, the user is
>>> prompted to specify how links will be updated. Otherwise,
>>> this argument is one of the values listed in the following table.
>>>
>>> Value Meaning
>>> 0 Doesn't update any references
>>> 1 Updates external references but not remote references
>>> 2 Updates remote references but not external references
>>> 3 Updates both remote and external references
>>>
>>>
>>> Hmm..
>>>
>>> Is it possible for you to run the PHP script from the command
>>> line on the server using the same credentials used by IIS (or
>>> the app pool used). I'm still not 100% uptodate with IIS+PHP
>>> security using FastCGI. If you can get the script running,
>>> make sure you turn on visibility within/for Excel so you can
>>> see what is happening.
>>>
>>> --
>>> -----
>>> Richard Quadling
>>> Zend Certified Engineer :
>>> http://zend.com/zce.php?c=3DZEND002498&r=3D213474731
>>> "Standing on the shoulders of some very clever giants!"
>>>
>>
>
> I have a Type Library Viewer which allows me to see what the library
> actually has to offer. Sometimes the docs are out of date.
>
> A typelib is essentially a self-documenting library.
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D2134=
74731
> "Standing on the shoulders of some very clever giants!"
>
--=20
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
"Standing on the shoulders of some very clever giants!"
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php