Windows 98 - MS Office 2000 Apache 1.3.9 Windows PHP4.02 Dev (08-20-00) Running as CGI |
$instance = new COM("$identifier"); ?> |
$instance->[Object]->[method1]->[method2]->..->[property]; ?> |
bool com_set(class com_object, string property name, string property_value); mixed com_get(class com_object, string property_name); ?> |
$Instance = new COM(string "Component name", string "remote_server_address"); ?> |
MS Word: "Word.Application" or "Word.Application.9" MS Excel: "Excel.Application" or "Excel.Sheet" ADOBE Acrobat: "Exch.application" or "PdfDistiller.PdfDistiller" |
#实例化一个对象 $word = new COM("word.application") or die("Unable to instantiate Word"); #取得并显示版本 print "Loaded Word, version {$word->Version} "; #另一种方法去取得版本 $testversion = com_get($word->application,version); print "Version using Com_get(): $testversion "; #使其可见 $word->Visible = 1; #创建新文件 $word->Documents->Add(); #写字符 $word->Selection->TypeText("This is a test..."); #保存 $word->Documents[1]->SaveAs("Useless test.doc"); #关闭 $word->Quit(); ?> |
#打开workbook和它的sheet, #本例使用一个电子表格是Excel安装时自带的SOLVSAMP.XLS $workbook = "C:Program FilesMicrosoft officeOfficeSamplesSOLVSAMP.XLS"; $sheet = "Quick Tour"; #实例化一个组件的对象 $ex = new COM("Excel.sheet") or Die ("Did not connect"); #取程序名称和版本 print "Application name:{$ex->Application->value} " ; print "Loaded version: {$ex->Application->version} "; #打开工作本使我们可使用它 $wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open"); #预保存原来的工作本,创建一个工作本的复本 $ex->Application->ActiveWorkbook->SaveAs("Ourtest"); #$ex->Application->Visible = 1; #本句去注释让Excel可见 # 读写一个单元格在一个新的工作表中 # 我们可以读到这个单元格 E11 (Advertising in the 4th. Quarter) $sheets = $wkb->Worksheets($sheet); #Select the sheet $sheets->activate; #Activate it $cell = $sheets->Cells(11,5) ; #Select the cell (Row Column number) $cell->activate; #Activate the cell print "Old Value = {$cell->value} "; #Print the value of the cell:10000 $cell->value = 15000; #Change it to 15000 print "New value = {$cell->value} ";#Print the new value=15000 #最后,用新值重新计算这个单元格 $sheets->Calculate; #必须的如果要计算,手动则是可选的 #可看到效果总价值(E13单元格) $cell = $sheets->Cells(13,5) ; #Select the cell (Row Column number) $number = Number_format($cell->value); print "New Total cost =$$number - was $47,732 before. "; #根据计算公式,广告影响了公司的开销,这里将显示 $57,809 #使用Excel内建的函数 # PMT(percent/12 months,Number of payments,Loan amount) $pay = $ex->application->pmt(0.08/12,10,10000); $pay = sprintf("%.2f",$pay); print "Monthly payment for $10,000 loan @8% interest /10 months: $ $pay "; #Should print monthly payment = $ -1,037.03 #可选,保存 $ex->Application->ActiveWorkbook->SaveAs("Ourtest"); #关闭,不提问 $ex->application->ActiveWorkbook->Close("False"); unset ($ex); ?> |
$pdf = new COM("pdfdistiller.pdfdistiller.1"); ?> |
$pdf->FileToPdf ($psfile, strOutputPDF '', strJobOptions ""); ?> |
$pdf->FileToPdf ($psfile, "", ""); #这儿$psfile 可以是 Myfile.ps 将返回 Myfile.pdf 文件。 ?> |