COMFunctionsinPHP4(Windows)_PHP
Using the PHP4 COM functions with MS Excel
As for the Word example above, study the code with the help from the Visual Basic Editor ObjectBrowser for Excel.
#Set the workbook to use and its sheet. In this example we use a spreadsheet that
#comes with the Excel installation called: SOLVSAMP.XLS
$workbook = "C:\Program Files\Microsoft office\Office\Samples\SOLVSAMP.XLS";
$sheet = "Quick Tour";
#Instantiate the spreadsheet component.
$ex = new COM("Excel.sheet") or Die ("Did not connect");
#Get the application name and version
print "Application name:{$ex->Application->value}
" ;
print "Loaded version: {$ex->Application->version}
";
#Open the workbook that we want to use.
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
#Create a copy of the workbook, so the original workbook will be preserved.
$ex->Application->ActiveWorkbook->SaveAs("Ourtest");
#$ex->Application->Visible = 1; #Uncomment to make Excel visible.
# Read and write to a cell in the new sheet
# We want to read the cell 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
#Eventually, recalculate the sheet with the new value.
$sheets->Calculate; #Necessary only if calc. option is manual
#And see the effect on total cost(Cell 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.
";
#Should print $57,809 because the advertising affects the Corporate overhead in the
# cell formula.
#Example of use of the built-in functions in Excel:
#Function: 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
#Optionally, save the modified workbook
$ex->Application->ActiveWorkbook->SaveAs("Ourtest");
#Close all workbooks without questioning
$ex->application->ActiveWorkbook->Close("False");
unset ($ex);
?>
This example should get you going with the Excel COM and PHP. Of course there are many more objects to use. Writing an OOP wrapper for the principal functions will make access to the excel objects even easier.
Using PHP COM with Adobe Distiller
This last example is for a non-MS program: If your program has produced a PostScript document, it may be interesting to transform it (Distill it) to a PDF document. Adobe has a program called Distiller with a windows version that can be instantiated, with the following code:
$pdf = new COM("pdfdistiller.pdfdistiller.1");
?>
Note that the OLE Identifier name is not obvious, especially when the distiller documentation (Adobe's Technical Note #5158) refers to it as "pdfdistiller."
The principal method to distill a document is:
$pdf->FileToPdf ($psfile, strOutputPDF '', strJobOptions "");
?>
Where $psfile is the name of the PostScript file, strOutputPDF is the name for the output PDF file. StrJobOptions is the name of the parameters file for Distiller. The two last parameters of the method can be left blank to use the same name, the PS file for the PDF file and to use the default Job options file. For example:
$pdf->FileToPdf ($psfile, "", "");
#Where $psfile could be Myfile.ps and the result file: Myfile.pdf
?>
There are more methods and properties that can be used with Distiller. If you are interested, look at the Adobe's technical note.
Caveats/Possible problems
If there are some errors in your code, you may instantiate the object and your program may not close before it times out. Worst of all, the application may retentively be instantiated. As a result, several copies may lay around in your programs list and interfere after you have corrected the problem. The solution: After fixing the bug, clean up (CTRL+ALT+Delete> and End Task) all the instances in the program list before you restart. For this same reason, always close the application at the end of your code and unlink the instance.
You may experience some oddities with com_get and com_set. For example: $Version = Com_get($instance->Application,"Version"); Works with Word, but produces an error with Excel.
Some Objects won't be instantiated by PHP4, it appears that these objects need a custom interface that PHP4-COM doesn't support.
Why use it?
Hopefully, these three examples have shown you the ropes. PHP COM allows the connection to many Windows programs inside a PHP script. The code is simpler than ASP's and can be integrated with the rest of PHP's powerful database functions. Microsoft markets the COM technology everywhere and under different names and architectures, like COM+(Combine COM with Microsoft Transaction Server MTS), ADO, OLE DB, OWC, Windows DNA, etc. PHP and Apache, working together, are now offering an open source solution to this confusion.
http://phpclasses.upperdesign.com/browse.html?package=86
--Alain
PS: See the EXCEL class using the COM interface at:

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

想了解更多關於開源的內容,請造訪:51CTO鴻蒙開發者社群https://ost.51cto.com運行環境DAYU200:4.0.10.16SDK:4.0.10.15IDE:4.0.600一、建立應用程式點擊File- >newFile->CreateProgect。選擇模版:【OpenHarmony】EmptyAbility:填寫項目名,shici,應用包名com.nut.shici,應用儲存位置XXX(不要有中文,特殊字符,空格)。 CompileSDK10,Model:Stage。 Device

機器之能報道編輯:吳昕國內版的人形機器人+大模型組隊,首次完成疊衣服這類複雜柔性材料的操作任務。隨著融合了OpenAI多模態大模型的Figure01揭開神秘面紗,國內同行的相關進展一直備受關注。就在昨天,國內"人形機器人第一股"優必選發布了人形機器人WalkerS深入融合百度文心大模型後的首個Demo,展示了一些有趣的新功能。現在,得到百度文心大模型能力加持的WalkerS是這個樣子的。和Figure01一樣,WalkerS沒有走動,而是站在桌子後面完成一系列任務。它可以聽從人類的命令,折疊衣物

人工智慧(AI)已經改變了許多行業的遊戲規則,使企業能夠提高效率、決策和客戶體驗。隨著人工智慧的不斷發展和變得越來越複雜,企業投資於合適的基礎設施來支援其開發和部署至關重要。這個基礎設施的一個關鍵方面是IT和數據科學團隊之間的協作,因為兩者在確保人工智慧計畫的成功方面都發揮著關鍵作用。人工智慧的快速發展導致對運算能力、儲存和網路能力的需求不斷增加。這種需求為傳統IT基礎架構帶來了壓力,而傳統IT基礎架構並非設計用於處理AI所需的複雜和資源密集型工作負載。因此,企業現在正在尋求建構能夠支持AI工作負

comcn和com的區別:1、comcn和com在含義等方面有區別,在訪問速度上沒有區別;2、comcn屬於國際域名,是全球通用頂級域名,供商業機構使用,而cn是中國的公司域名,國內商業機構,國內域名,必須企業才可以備案;3、搜尋的優先順序是cn先會去搜尋.cn,找到.cn伺服器後,再由.cn伺服器搜尋.com;4、cn由cnnic中國網路中心管理,com的管理機構在國外。

曾幾何時,當我還是一名初出茅廬的電腦專業應屆生的時候,在招聘網站上瀏覽了很多招聘貼,眼花繚亂的技術職位讓我摸不著頭腦:研發工程師、運維工程師、測試工程師...大學期間專業課馬馬虎虎,更談不上有什麼技術視野,對於具體從事那個技術方向並沒有什麼明確的想法。直到一位學長對我說:「做運維吧,做運維不用天天寫程式碼,會玩Liunx就行!比做開發輕鬆多了!」我選擇了相信......入行十多年,吃過很多苦,背了很多鍋,弄死過服務器,經歷過部門裁員,如果有人現在跟我說做維運比開發簡單,那我會

我們中的許多人在Python 程式碼中一遍又一遍地看到這個程式碼片段:with open('Hi.text', 'w') as f: f.write("Hello, there") 但是,我們中的有些人不知道with 有什麼用,以及為什麼我們需要在這裡使用它。在此閱讀中,您將找到關於 with 可解決的幾乎所有問題。讓我們開始吧!首先,讓我們考慮一下如果不使用 with 關鍵字我們需要做什麼。在這種情況下,我們需要先開啟檔案並嘗試執行 write。不管成功與否,我們最好在

it是資訊技術,主要用於管理和處理資訊所採用的各種技術的總稱,it是當今社會中不可或缺的一部分,透過改變生活和工作方式,it帶來了很多便利和機會,並且還有巨大的潛力待挖掘。隨著it的不斷發展,期待更多新的應用和技術的出現,為生活帶來更大的改變。

隨著企業尋求可以根據不斷變化的業務需求進行擴展和縮減的運算和儲存資源,雲端的採用率急劇上升。但即使考慮到雲端運算的成本和敏捷性優勢,人們對另一種部署模型的興趣也越來越高——邊緣運算,也就是在資料來源或附近進行的運算。它可以支援新的用例,尤其是對現代商業成功至關重要的創新人工智慧和機器學習應用。在《麻省理工科技評論》(MIT Technology Review)主辦的「未來計算」(Future Compute)大會上,三位工業技術專家表示,這項優勢的前景在於數據。具體來說,無論是工廠、自動駕駛汽車或
