优化项目结构, 增加表格和文档插件

This commit is contained in:
jianxin committed 2025-04-01 15:09:39 +08:00
1 parent 0d6e543a6f
commit 685813b443
30 files changed
+539 -125

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
//这个函数在整个wps加载项中是第一个执行的
function OnAddinLoad(ribbonUI) {
if (typeof (window.Application.ribbonUI) != "object") {
window.Application.ribbonUI = ribbonUI
}
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
window.Application.Enum = WPS_Enum
}
return true
}
function OnAction(control) {
const eleId = control.Id
switch (eleId) {
case "btnShowAbout":
{
alert("关于我们\n\n作者:Jianxin\n\n版本:1.0.0\n\n说明:自动化插件\n\n感谢使用!")
}
break;
default:
break
}
return true
}
function GetImage(control) {
const eleId = control.Id
switch (eleId) {
case "btnShowAbout":
return "images/about.svg"
default:
;
}
return "images/newFromTemp.svg"
}
+19
View File
@@ -0,0 +1,19 @@
//在后续的wps版本中,wps的所有枚举值都会通过wps.Enum对象来自动支持,现阶段先人工定义
var WPS_Enum = {
msoCTPDockPositionLeft: 0,
msoCTPDockPositionRight: 2
}
function GetUrlPath() {
let e = document.location.toString()
return -1 != (e = decodeURI(e)).indexOf("/") && (e = e.substring(0, e.lastIndexOf("/"))), e
}
/**
* 通过wps提供的接口执行一段脚本
* @param {*} param 需要执行的脚本
*/
function shellExecuteByOAAssist(param) {
if (wps != null) {
wps.OAAssist.ShellExecute(param)
}
}
+65
View File
@@ -0,0 +1,65 @@
let wpsInstance = null;
function InvokeFromXbot(param) {
// 1. 解析参数, 如果不是字符串, 则转换为字符串, 并用json解析, 解析失败直接retrun
if (typeof param !== 'string') {
param = JSON.stringify(param);
}
try {
param = JSON.parse(param);
} catch (e) {
return { msg: '参数解析失败', code: -1 };
}
// 2. 判断是否有method字段, 如果没有直接return
if (!param.method) {
return { msg: '参数错误', code: -2 };
}
// 3. 获取 method 字段对应的方法和 args 参数
let method = param.method;
let args = null;
try {
args = JSON.parse(param.args);
} catch (e) {
args = {};
}
console.log("method:", method);
console.log("args:", args);
// confsole.log("args", typeof args);
// 4. 判断 method 是否为 inject, 如果是则执行注入方法, 其他走默认方法执行调用函数
if (method === 'inject') {
let code = args.code;
console.log("start eval code");
console.log(code);
console.log(new Function(code)());
wpsInstance = new Function(code)(); // 执行并获取返回值
console.log("success eval code");
return { message: "inject ok", code: 0 }
}
// 5. 判断是否有 wpsInstance, 如果没有直接return
if (!wpsInstance) {
return {msg: '未注入', code: -3};
}
// 6. 判断 wpsInstance 是否有 method 方法, 如果没有直接return
if (!wpsInstance[method]) {
return {msg: '方法不存在', code: -4};
}
// 7. 执行 wpsInstance 的 method 方法, 并返回结果
try {
const result = wpsInstance[method](args ?? null);
return {msg: '执行成功', code: 0, data: result};
} catch (e) {
return {msg: '执行失败', code: -5};
}
}