Quicker调用wps表格中的js宏代码,可以通过Quicker动态传递js代码,这样就可以避免用(Office软件辅助模块)调用一次而运行两次代码的情况,还可以动态(传递\接收)变量
https://getquicker.net/subprogram?id=9ee528ab-3134-47a4-d476-08ddb495533f wps表格子程序
https://getquicker.net/subprogram?id=439ce4ed-875d-4215-d47d-08ddb495533f wps文档子程序
https://getquicker.net/Sharedaction?code=426fe848-c828-4876-d477-08ddb495533f 动作
1.wps表格中的js宏代码:巧用eval(a)
function g1(a)
{
return eval(a)
}
2.Quicker中C#的函数 wps表格
//.cs 文件类型,便于外部编辑时使用
// 引用必要的命名空间
using Excel = Microsoft.Office.Interop.Excel;
// Quicker将会调用的函数。可以根据需要修改返回值类型。
public static void Exec(Quicker.Public.IStepContext context)
{
Excel.Application excelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
var oldValue = context.GetVarValue("g0");
var bb=excelApp.Run("g1",oldValue);
context.SetVarValue("g2", bb);
}
2.Quicker中C#的函数 wps文档
//.cs 文件类型,便于外部编辑时使用
// 引用必要的命名空间
using Word=Microsoft.Office.Interop.Word;
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{
var oldValue = context.GetVarValue("g0");
var winObj = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");//获取当前启动的word程序
var bb=winObj.Run("g1",oldValue);
context.SetVarValue("g2", bb);
}
注意:推荐将有js宏代码的文件保存为a.xla加载宏文件,再通过加载项加载此文件
这样就可以再不删除此文件的情况下,不用每次都写此代码和原文件不能保存的状况
之后就可以多次调用运行js代码(用的时候可以去加载项对此函数打勾,如果感到碍事,就取消打勾加载)
提醒不要写与此函数重名的函数,要保证此函数的唯一性
这都是针对已打开当前活动文档的代码:wps文档也可以,我刚才试了一下
wps文档的c#代码:
using Word=Microsoft.Office.Interop.Word;
// Quicker将会调用的函数
public static void Exec(Quicker.Public.IStepContext context)
{
var oldValue = context.GetVarValue("g0");
var winObj = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");//获取当前启动的word程序
var bb=winObj.Run("g1",oldValue);
context.SetVarValue("g2", bb);
}