ActiveX 仅在激活 IE 9 控制台时工作

ActiveX only working when IE 9 Console is activated

我正在构建一个小型 Web 应用程序,需要通过 ActiveX 和 Javascript(以及 IE9...)访问 Powerpoint 以自动构建报告。我正在使用 ActiveX,因为我无法在服务器端生成 Powerpoint 文件(尽管我非常希望这样做)。

我现在的代码非常简单,因为我才刚刚开始:

// Creating the ActiveX Powerpoint control
var ppt;
try{
    ppt = new ActiveXObject("Powerpoint.Application");
}catch(e){
    if (e instanceof ReferenceError)
        alert("Your browser might not be compatible with this function. Please use Internet Explorer.");
    else
        alert("An error happened: " + e);
}
console.log("ActiveX Object created");

// Openning Powerpoint, make it visible
ppt.Visible = 1;

// Creating a new Presentation, and adding a blank (1 slide, 1 = ppLayoutBlank) Slide
ppt.Presentations.Add();
ppt.ActivePresentation.Slides.Add(1, 1);

在我的计算机上,即使我允许它通过 "An ActiveX control on this page might be dangerous; Do you allow it to execute?"(直接从法语引出)执行,ActiveX 控件也不会启动 Powerpoint。

但是,如果我启动 Developper Console,它会神奇地 运行s。而且,在另一台装有 IE 11 的计算机上,在我允许 ActiveX 控件执行后,它工作正常。

我认为我的 IE 安全设​​置是正确的,因此我想不出任何我不知道的 IE 故障。我正在使用 IE 9.0.8112.16421 64 位。

我怎样才能把这个代码很好地运行?提前谢谢你!

提醒:IE 中的 console.log 仅在开发者控制台打开时有效。 如果开发者控制台关闭,它会停止脚本,因为 consoleundefined.

在您的代码中,尝试更改:

console.log("ActiveX Object created");

try{console.log("ActiveX Object created")}catch(err){} 或注释行://.