gpt4 book ai didi

php - 使用 PHP 或 PHP-CLI 实现 OLE 自动化?

转载 作者:行者123 更新时间:2023-12-04 06:53:34 25 4
gpt4 key购买 nike

我在这里阅读 http://www.daniweb.com/code/snippet217293.html#有可能的。

应该在 PHP.Ini 或其他地方激活什么才能使其工作?有 Excel 的例子吗?

最佳答案

如果您在 Windows 上运行 php,它将默认安装。不过,您可以设置一些选项。我认为不需要它们:

http://www.php.net/manual/en/com.configuration.php

至于使用excel的例子?这是我从 Excel 电子表格中提取值时发现的一个小片段:

<?PHP
$filename = "c:/spreadhseet/test.xls";
$sheet1 = 1;
$sheet2 = "sheet2";
$excel_app = new COM("Excel.application") or Die ("Did not connect");
print "Application name: {$excel_app->Application->value}\n" ;
print "Loaded version: {$excel_app->Application->version}\n";
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook");
$Worksheet = $Workbook->Worksheets($sheet1);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
$Worksheet = $Workbook->Worksheets($sheet2);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
#To close all instances of excel:
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);
?>

关于php - 使用 PHP 或 PHP-CLI 实现 OLE 自动化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2778028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com