PHP: COM t�mogat� f�ggv�nyek Windowshoz - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousccvs_voidCOMnext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

VIII. COM t�mogat� f�ggv�nyek Windowshoz

Ezek a f�ggv�nyek csak Windows alatt �rhet�ek el, a PHP 4-es verzi�j�ban ker�ltek bevezet�sre.

Tartalom
COM -- COM class
VARIANT -- VARIANT class
com_addref --  Increases the components reference counter.
com_get -- COM komponenes egy tulajdons�g�nak �rt�k�t adja vissza
com_invoke -- Egy COM komponens egy met�dus�t h�vja
com_isenum -- Grabs an IEnumVariant
com_load_typelib -- Loads a Typelib
com_load -- L�trehoz egy �j referenci�t egy COM komponensre
com_propget -- COM komponenes egy tulajdons�g�nak �rt�k�t adja vissza
com_propput -- �rt�ket ad COM komponenes egy tulajdons�g�nak
com_propset -- �rt�ket ad COM komponenes egy tulajdons�g�nak
com_release --  Decreases the components reference counter.
com_set -- �rt�ket ad COM komponenes egy tulajdons�g�nak
User Contributed Notes
COM t�mogat� f�ggv�nyek Windowshoz
add a note about notes
[email protected]
20-Dec-2000 06:45

As Jason ([email protected]) as demonstrated in his code example, there is a PHP database wrapper class library that can connect to ADO available called ADODB.

It is available from and supports many databases both on Windows and Linux.

Modelled after ADO, so it should be easy for Windows programmers to learn.

[email protected]
31-Mar-2001 11:37

I thought i'd share with those of you unfamiliar with one of the cool things
about developing php on win32 systems..



This is a good article, but i don't think the author hit the nail on the
head showing how useful this can be.

Now, checkout this article:


Notice how he describes 1) how to build a com object & 2) how to call and
use the com object from ASP.

In php, this is how you would call the same object:

<?
$instance = new COM("Checkyear.LeapYear");
$isleapyear = $instance->IsLeapYear($year);
$instance->close();
if($isleapyear) {
echo "The <b>$year</b> is a leap year";
}
else {
echo "The <b>$year</b> is not a leap year";
}
?>

I hope this helps someone.. you can contact me at [email protected] if
you would like to discuss this further.

[email protected]
28-Feb-2002 03:11

now in PHP >=4.0.6
programming in window can use the
ADO through the COM like this:
$dbconn=new COM ("ADODB.Connection") or die ("connection create fail");
$dbconn->Open("Provider=sqloledb;Data Source=ndht;Initial Catalog=printers;User Id=printers;Password=printers;");
$rec=new COM("ADODB.Recordset") or die ("create Recordset error");
while (!$rec->EOF)
{
echo $rec->fields["fieldname"]->value."
";
$rec->movenext();
}
$rec->close();
$dbconn->close();

but there's still a little question of working with the image field of mssql server.

[email protected]
07-Mar-2002 06:59

I thought this excel chart example could be useful.

Note the use of Excel.application vs Excel.sheet.

<pre>
<?php
print "Hi";
#Instantiate the spreadsheet component.
# $ex = new COM("Excel.sheet") or Die ("Did not connect");
$exapp = new COM("Excel.application") or Die ("Did not connect");

#Get the application name and version
print "Application name:{$ex->Application->value}
" ;
print "Loaded version: {$ex->Application->version}
";

$wkb=$exapp->Workbooks->add();
#$wkb = $ex->Application->ActiveWorkbook or Die ("Did not open workbook");
print "we opened workbook
";

$ex->Application->Visible = 1; #Make Excel visible.
print "we made excell visible
";

$sheets = $wkb->Worksheets(1); #Select the sheet
print "selected a sheet
";
$sheets->activate; #Activate it
print "activated sheet
";

#This is a new sheet
$sheets2 = $wkb->Worksheets->add(); #Add a sheet
print "added a new sheet
";
$sheets2->activate; #Activate it
print "activated sheet
";

$sheets2->name="Report Second page";

$sheets->name="Report First page";
print "We set a name to the sheet: $sheets->name
";

# fills a columns
$maxi=20;
for ($i=1;$i<$maxi;$i++) {
$cell = $sheets->Cells($i,5) ; #Select the cell (Row Column number)
$cell->activate; #Activate the cell
$cell->value = $i*$i; #Change it to 15000
}

$ch = $sheets->chartobjects->add(50, 40, 400, 100); # make a chartobject

$chartje = $ch->chart; # place a chart in the chart object
$chartje->activate; #activate chartobject
$chartje->ChartType=63;
$selected = $sheets->range("E1:E$maxi"); # set the data the chart uses
$chartje->setsourcedata($selected); # set the data the chart uses
print "set the data the chart uses
";

$file_name="D:/apache/Apache/htdocs/alm/tmp/final14.xls";
if (file_exists($file_name)) {unlink($file_name);}
#$ex->Application->ActiveWorkbook->SaveAs($file_name); # saves sheet as final.xls
$wkb->SaveAs($file_name); # saves sheet as final.xls
print "saved
";

#$ex->Application->ActiveWorkbook->Close("False");
$exapp->Quit();
unset($exapp);
?>

</pre>

Alex Madon

[email protected]
02-Apr-2002 10:01

An easy way to send e-mail using your default Outlook account:
<?
$objApp = new COM("Outlook.Application");
$myItem = $objApp->CreateItem(olMailItem);
$a=$myItem->Recipients->Add("[email protected]");
$myItem->Subject="Subject";
$myItem->Body="This is a Body Section now.....!";
$myItem->Display();
$myItem->Send();
?>

[email protected]
19-Apr-2002 10:34

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

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

// if you want see thw World interface the value must be '1' else '0'
$word->Visible = 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 = null;

[email protected]
28-Jun-2002 04:48

Complementing Alex's Excell Example, let's print the SpreadSheet to a PDF file using Acrobat Distiller:

$wkb->PrintOut(NULL, NULL, NULL, NULL, "Acrobat Distiller");

There you go!!!

nospam @ bol .com.br
21-Aug-2002 09:30

This is a sample to make a parametrized query using ADO via COM, this sample was used with Foxpro but will work's with most ADO complient databases. This was tested on IIS with WIN XP pro.

<?
// Create the main connection
$dbc = new COM("ADODB.Connection") or die ("connection create fail");
$dbc->Provider = "MSDASQL";
$dbc->Open("FoxDatabase");
// Creates a temporary record set
$RSet = new COM("ADODB.Recordset");
// Create one ADO command
$cm = new COM("ADODB.Command");
$cm->Activeconnection = $dbc;
// the ? inside values will be the parameters $par01 and $par02
$cm->CommandText = "Insert Into testtable ( mycharfield,mymemofield) VALUES (?,?)" ;
$cm->Prepared = TRUE;
// Creates and append 2 parameters
$par01 = $cm->CreateParameter('ppar01',129,1,50,'ABCDEFGHIKL');
$cm->Parameters->Append($par01);
$par02 = $cm->CreateParameter('ppar01',129,1,50,'123456789012346789');
$cm->Parameters->Append($par02);
// Call 10 times the exec comand to show 10 different queries
for ($i = 1; $i <= 10; $i++) {
$par01->Value = 'Count '.$i;
$par02->Value = 'Passing here'.$i.' times';
$RSet = $cm->Execute;
}
$RSet = $dbc->Execute("select * from testtable");
while (!$RSet->EOF){
echo $RSet->fields["mycharfield"]->value.' ' ;
echo $RSet->fields["mymemofield"]->value ;
echo '
';
$RSet->movenext();
}
$RSet->close;
$dbc->close;
$cm->close;
$RSet = null;
$dbc = null;
$cm = null;
?>

[email protected]
27-Aug-2002 09:31

When first writing applications instancing COM objects I always faced the problem of the instanced program not terminating correctly although everything else worked fine. In fact the process had to be killed manually by using the task manager. When experimenting a bit I was able to isolate the cause for this peculiar behaviour to be illustrated by the sample code below:

<?php

//Accessing arrays by retrieving elements via function ArrayName(Index) works, but certainly is neither efficient nor good style
$excel=new COM("Excel.Application");
$excel->sheetsinnewworkbook=1;
$excel->Workbooks->Add();

$book=$excel->Workbooks(1);
$sheet=$book->Worksheets(1);

$sheet->Name="Debug-Test";
$book->saveas("C:\\debug.xls");

$book->Close(false);
unset($sheet);
unset($book);
$excel->Workbooks->Close();
$excel->Quit();
unset($excel);

//Accessing arrays as usual (using the [] operator) works, buts leads to the application not being able to terminate by itself
$excel=new COM("Excel.Application");
$excel->sheetsinnewworkbook=1;
$excel->Workbooks->Add();

$excel->Workbooks[1]->Worksheets[1]->Name="Debug-Test";
$excel->Workbooks[1]->saveas("C:\\debug.xls");

$excel->Workbooks[1]->Close(false);
$excel->Workbooks->Close();
$excel->Quit();
unset($excel);

?>

The sample code performs the same action twice and each time the file is properly created. Yet for some mysterious reason the instanced excel process won't terminate once you've accessed an array the way most programmers (especially those who do a lot of oop in c++) do! Therefore until the PHP developers become aware of this problem we'll have to use the inefficient coding style illustrated in the first example.

add a note about notes
previousccvs_voidCOMnext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Aug 31 06:19:44 2002 CEST