带有Javascript的Excel宏 [英] Excel Macros with Javascript

查看:141
本文介绍了带有Javascript的Excel宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用JavaScript中的宏操作excel电子表格,而不是默认的VBA。我可以使用以下VBA代码执行JavaScript代码

I wish to manipulate excel spreadsheets using macros in Javascript rather than the default VBA. I can execute javascript code using the following VBA code

'javascript to execute
Dim b As String
b = "function meaningOfLife(a,b) {return 42;}"

'VBA tool to run it
Dim o As New ScriptControl
o.Language = "JScript"
o.AddCode b
MsgBox o.Run("meaningOfLife", 0, 1)

这使我能够执行任意JavaScript,但是我无法从javascript环境中访问excel电子表格。有没有什么办法可以在javascript内在活动工作表中设置和获取工作表值?

this enables me to execute arbitrary javascript, however I do not have access to the excel spreadsheet from within the javascript environment. Is there any way I can set and get worksheet values in the active worksheet from within javascript?

推荐答案

这取决于什么样的 Excel程序你想要做的。

It depends what sort of "Excel programming" you want to do.

如果要操作Excel 文件,可以通过COM自动化,甚至ODBC在某种程度上,使用在Windows脚本环境下运行的JavaScript。

If you want to manipulate Excel files, you can do so via COM automation, or even ODBC to some degree, using JavaScript running under the Windows scripting environment.

但是,如果您希望让代码在活动的Excel会话中运行,访问者将看到它,更少的选项。

But if you want to have your code running within an active Excel session doing things the visitor will see, you have fewer options.

看到这个问题我发布了几年前,当我有一些JavaScript我想在Excel中运行,没有预算转换为VBA:

See this question I posted a few years back when I had some JavaScript I wanted to run within Excel and didn't have the budget to convert to VBA:

如何在Excel宏中使用JavaScript?

这篇关于带有Javascript的Excel宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆