(tips,javascript,office)客户端操作excel文档的注意事项

最近项目需要使用javascript将客户端上面的excel文档读取,于是继续网上搜索代码看到孟子大哥给别人的一段回复中给了一个new ActiveXobject(Application.Excel)的代码,我在页面中使用后出现了automation服务器不能创建对象的错误,查找了下大多数答案都是说没权限,改ie设置,但是具体的如何改正却是没说清楚,咱们中国论坛的这样的风气太害人了(回答问题从来很多人都不说清楚,简单的说下就完了),所以最后还是在国外某个论坛上面查到了解决方案:
======================================================
ref question:
The following javascript has been working just fine for the last 5 months.
Now, for no apparent reason, the following error occurs when the script is
run.

"Automation server can't create object"


The script is below. Please note that the parameter passed to the function
is a valid path/filename.

I tried setting all browser security settings to "low", but this did not
resolve the problem.

Any suggestions are greatly appreciated.

-----------------------------------

<script language="JavaScript">
function startWord(strFile)
{
var myApp = new ActiveXObject("Word.Application");
if (myApp != null)
{
myApp.Visible = true;
myApp.Documents.Open(strFile);
}
}
</script>
ref solution:
 1.Undo what you just did, first of all. Then
you need to tweak the properties of the level that the site is in. Tools ?
Internet Options… ? choose tab Security ? click button Custom level ? scroll
to 'Run ActiveX controls and plug-ins' ? select ‘prompt’ or ‘enable’.
Presumably something 's changed there, probably we 'll never know how.
 2 That particular setting didn't fixed the problem. However, I decided to try
some of the others in that section. Turns out the problem has been resolved
by enabling the following setting "Initialize and script ActiveX control not
marked as safe.

======================================================
网上很多人说是用开始/运行/regsvr32 scrruning.dll来解决,可是很多时候使用这个并不一定能解决问题。我觉得很多情况下应该属于IE安全设置的问题,和运行不运行那个注册dll没关系。现在上面的论述已经可以说明不仅仅需要更改ie设置安全标签里面internet站点里面自定义站点,将运行未签名的activex控件以及是否初始化activex脚本并运行沟选上才能避免出现automation服务器不能创建对象的对话框。

原文地址:https://www.cnblogs.com/ocean2000/p/944241.html