为什么 VBA 函数不适用于 PHP 7?

Why does a VBA function does not work with PHP 7?

我刚刚将我的 Web 应用程序升级到 PHP 5.XXX 到 PHP 7.4.28.

到目前为止,我解决了大部分问题,但我一直停留在一个显然不再被识别的 VBA (DCOM) 函数上:

$myTable->Range->InsertBreak(8);

其中“8”表示 wdColumnBreak。

能否让我知道是否有任何替代语法可以使此分栏符正常工作?

非常感谢任何建议, 非常感谢

Considerations for server-side Automation of Office 文章陈述如下:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

我建议选择专为 server-side 执行而设计的组件。如果您只处理打开的 XML 文档,您也可以查看 Open XML SDK

经过一番折腾,我找到了以下解决方案:

$myNumber= new VARIANT(8, VT_I4);
$MyTable->Range->InsertBreak($myNumber);

基本上 InsertBreak 函数的参数必须被视为变体,而不是数字。 使用这种语法,它工作得很好。

我真的很想分享这个解决方案,因为我不喜欢这种方法“不再推荐这种技术,只使用最新的”... 迁移到新技术并不总是那么简单(甚至无法保证其可靠性)。

干杯