Jump to content

»»» Excel and Word are OK, but I can't access a Project file using COM :(


overday

Recommended Posts

Hi!

 

The system I'm currently developing needs to read information from a Microsoft Project and save to a database.

 

I'm trying to use COM, but no success.

 

Here's a simple working code to create a word document:

 

<?php

$word = new COM("word.application") or die("Unable to load Word");

echo "Word loaded, version {$word->Version}\n";

$word->Documents->Add();

$word->Selection->TypeText("Test");

$word->Documents[1]->SaveAs("test.doc");

$word->Quit();

$word = null;

?>

 

That works like a charm. Unfortunatelly, I couldn't find a single example of PHP accessing Project using COM. Then I tried this:

 

<?php

$project = new COM("msproject.application") or die("Unable to load Project");

?>

 

And a WINPROJ process was created. That was nice, but useless, because I get an error message when I try to use any method.

 

<?php

$project = new COM("msproject.application") or die("Unable to load Project");

$project->FileNew("");

?>

 

Results "Fatal error: Call to undefined method com::FileNew() in D:\FIGP\pms\upload.php on line 18".

 

Even quitting, that is probably a method of all Office applications, gives the same error.

 

<?php

$project = new COM("msproject.application") or die("Unable to load Project");

$project->Quit();

?>

 

Results "Fatal error: Call to undefined method com::Quit() in D:\FIGP\pms\upload.php on line 18".

 

I really need to read information from a MPP file, but I have no idea how to even create the project instance and create a new file.

 

Could somebody help, please?  ??? :'(

If you can't find any documentation you could always play with http://us3.php.net/get_class_methods :) I've never used COM, but I'd suspect finding documentation would be easier than trying to figure things out with get_class_methods()

If you can't find any documentation you could always play with http://us3.php.net/get_class_methods :) I've never used COM, but I'd suspect finding documentation would be easier than trying to figure things out with get_class_methods()

 

I think it doesn't work with COM

 

<?php

$excel = new COM("excel.application") or die("Unable to instantiate Excel");

echo "Loaded Excel, version {$excel->Version}\n";

 

echo "Class: ".get_class($excel)."\n";

 

$class_methods = get_class_methods(new COM("excel.application"));

echo "Number of methods: ".count($class_methods)."\n";

 

foreach ($class_methods as $method_name)

    echo $method_name."\n";

 

$excel->Quit();

$excel = null;

?>

 

Prints:

 

Loaded Excel, version 11.0

Class: com

Number of methods: 0

 

It DOES have methods, "$excel->Version" printed "11.0".

 

:o

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.