Interfacing PHP and Excel using OLE Automation: file access proble

S

SDelroen

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.

My guess is that Excel is run with different permissions in the second case,
so it cannot access the file, but I might be completely wrong.

Does someone have any experience in that matter ?

Thank you very much !
 
J

joel

did the code echo the First Date statement? If it did then the problem is
with excel. If not then the problem is the server isn't running the PHP
file. Are you getting any error messages? There may be a firewall in the
server that doesn't allow PHP files to run or on run for trusted users. You
didn't give details on how the code failed. What does BLOCKED mean?
 
S

SDelroen

Hi Joel, thanks for your reply.

Yes, first echo statements work fine, the problem occurs really when opening
the file.

Effectively, I should have been more precise on what "blocked": the script
is still running, but nothing happens.

If I RDP to the console on the server, in the taskmgr I can see the
EXCEL.EXE process created by PHP, and the file it Excel is trying to open is
locked for writing (ie. if I open it by double-clicking, Excel proposes me to
access it read-only).

One interesting thing: I am using the domain integrated authentication in
IIS for this website; if I try to open the locked file by double-clicking it,
Excel tells me the file is locked by MY account, though the EXCEL.EXE process
is run by Console.

There is no firewall on this server.

I might have found the problem: the file I am trying to open has external
links. With a "normal" file it works fine.

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/lib....interop.excel.workbooks.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.

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?

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 !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top