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

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

+74
View File
@@ -0,0 +1,74 @@
---
kind: pipeline
type: docker
name: default
platform:
arch: amd64
steps:
- name: build
image: node:slim
commands:
- npm config set registry http://mirrors.cloud.tencent.com/npm/
- npm config get registry
- npm install -g wpsjs
- wpsjs publish -s https://wps.woni.link/jsplugindir/
- name: upload plugin
image: appleboy/drone-scp
pull: never
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_user
port: 22
password:
from_secret: ssh_key
tags: 0.1
target: /data/www-data/xbotwps
source: ./wps-addon-build/*
- name: upload pushlish.html
image: appleboy/drone-scp
pull: never
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_user
port: 22
password:
from_secret: ssh_key
tags: 0.1
target: /data/www-data/xbotwps
source: ./wps-addon-publish/publish.html
- name: adjust dirctory
image: appleboy/drone-ssh
pull: never
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_user
port: 22
password:
from_secret: ssh_key
script:
- cd /data/www-data/xbotwps/wps-addon-build
- rm -rf /data/www-data/xbotwps/jsplugindir
- mkdir /data/www-data/xbotwps/jsplugindir
- mv ./* ../jsplugindir
- cd /data/www-data/xbotwps/wps-addon-publish
- mv ./* ../jsplugindir
- rm -rf /data/www-data/xbotwps/wps-addon-build
- rm -rf /data/www-data/xbotwps/wps-addon-publish
trigger:
branch:
include:
- main
- /^release-.*$/
+27 -3
View File
@@ -1,6 +1,4 @@
# XBot 文字插件 # WPS 插件自动化实现
## 配置相关 ## 配置相关
@@ -11,8 +9,34 @@
## 发版相关 ## 发版相关
## 自动安装插件
安装目录
windows: %Appdata%\kingsoft\wps\jsaddons
linux: .local/share/Kingsoft/wps/jsaddons
authwebsite.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<websites>
<website origin="null" status="enable" name="xbotwps"/>
</websites>
```
publish.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<jsplugins>
<jsplugin enable="enable_dev" url="C:\Users\32075\OneDrive\文档\Code\RPA_Script\wps-js-extension\XbotWps\wps-addon-build\xbotwps.7z" install="null" version="1.0.0" type="wps" customDomain="" name="xbotwps"/>
</jsplugins>
```
## 资料相关 ## 资料相关
- https://open.wps.cn/previous/docs/client/wpsload - https://open.wps.cn/previous/docs/client/wpsload
- https://gitee.com/wpsoa/wpsoa - https://gitee.com/wpsoa/wpsoa
- https://blog.csdn.net/huaermeier/article/details/132502705
- https://club.excelhome.net/thread-1671577-1-1.html
-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><style type="text/css">.skinbaseDark,.skinbaseLight,.skinthemeDark{fill-rule:evenodd;}.skinbaseDark,.skinbaseLight{opacity:0.8;}.skinbaseLight{fill:#838383;}.skinthemeDark{fill:#5789d9;}</style></defs><title>编辑文字</title><path class="skinbaseDark" d="M21,23H2a2,2,0,0,1-2-2V2A2,2,0,0,1,2,0H21a2,2,0,0,1,2,2V21A2,2,0,0,1,21,23ZM22,2a1,1,0,0,0-1-1H2A1,1,0,0,0,1,2V21a1,1,0,0,0,1,1H21a1,1,0,0,0,1-1Z"/><path class="skinbaseLight" d="M21.5,12h-3a.5.5,0,1,1,0-1h3a.5.5,0,1,1,0,1Zm-10,10a.50005.50005,0,0,1-.5-.5v-3a.5.5,0,1,1,1,0v3A.50005.50005,0,0,1,11.5,22Zm0-19a.50005.50005,0,0,1-.5-.5v-1a.5.5,0,1,1,1,0v1A.50005.50005,0,0,1,11.5,3Zm-7,9h-3a.5.5,0,1,1,0-1h3a.5.5,0,1,1,0,1Z"/><path class="skinthemeDark" d="M17.9993,18.9997H16.9367L15.27,14H7.7281L6.0617,18.9997H4.9991L8.9988,6.9993h0a2.92165,2.92165,0,0,1,2.5-2,2.75159,2.75159,0,0,1,2.5,2h0ZM12.9363,6.9993a1.2901,1.2901,0,0,0-1.4375-.9375,1.39754,1.39754,0,0,0-1.4375.9375h0L8.0613,13h6.8753L12.9362,6.9993h.0001Z"/></svg>
-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><style type="text/css">.skinbaseDark,.skinthemeDark{fill-rule:evenodd;}.skinbaseDark{opacity:0.8;}.skinthemeDark{fill:#5789d9;}</style></defs><title>艺术字大小</title><path class="skinbaseDark" d="M17.9993,18.9997H16.9367L15.27,14H7.7281L6.0617,18.9997H4.9991L8.9988,6.9993h0a2.92165,2.92165,0,0,1,2.5-2,2.75159,2.75159,0,0,1,2.5,2h0ZM12.9363,6.9993a1.2901,1.2901,0,0,0-1.4375-.9375,1.39754,1.39754,0,0,0-1.4375.9375h0L8.0613,13h6.8753L12.9362,6.9993h.0001Z"/><path class="skinthemeDark" d="M23,21v1a1,1,0,0,1-1,1H21a1,1,0,0,1-1-1H3a1,1,0,0,1-1,1H1a1,1,0,0,1-1-1V21a1,1,0,0,1,1-1V4A1,1,0,0,1,0,3V2A1,1,0,0,1,1,1H2A1,1,0,0,1,3,2H20a1,1,0,0,1,1-1h1a1,1,0,0,1,1,1V3a1,1,0,0,1-1,1V20A1,1,0,0,1,23,21ZM1,21.6a.4.4,0,0,0,.4.4h.2a.4.4,0,0,0,.4-.4v-.2a.4.4,0,0,0-.4-.4H1.4a.4.4,0,0,0-.4.4ZM2,2.4A.4.4,0,0,0,1.6,2H1.4a.4.4,0,0,0-.4.4v.2a.4.4,0,0,0,.4.4h.2A.4.4,0,0,0,2,2.6ZM20,3H3A1,1,0,0,1,2,4V20a1,1,0,0,1,1,1H20a1,1,0,0,1,1-1V4A1,1,0,0,1,20,3Zm2-.6a.4.4,0,0,0-.4-.4h-.2a.4.4,0,0,0-.4.4v.2a.4.4,0,0,0,.4.4h.2a.4.4,0,0,0,.4-.4ZM21.6,21h-.2a.4.4,0,0,0-.4.4v.2a.4.4,0,0,0,.4.4h.2a.4.4,0,0,0,.4-.4v-.2A.4.4,0,0,0,21.6,21Z"/></svg>
-19
View File
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<style type="text/css">
.skinbaseDark{opacity:0.8;enable-background:new ;}
.skinthemeDark{fill:#5789D9;}
</style>
<path class="skinbaseDark" d="M13,23h-1.4c-0.1,0-0.2,0-0.3-0.1c-0.7-0.2-0.9-0.6-1.3-0.9l-5-5H1.6C0.7,17,0,16.3,0,15.4V8.6
C0,7.7,0.7,7,1.6,7H5l5-5c0.4-0.4,0.6-0.8,1.3-0.9C11.4,1,11.5,1,11.6,1H12l0,0l0,0h1c0.6,0,1,0.5,1,1v20C14,22.5,13.6,23,13,23z
M13,2.4C13,2.2,12.8,2,12.6,2H12c-0.5,0-0.9,0.2-1.1,0.4c0.1-0.1,0,0,0,0C10.8,2.6,7.3,6,5.3,8H1.6C1.3,8,1,8.3,1,8.6v6.8
C1,15.7,1.3,16,1.6,16h3.7c2,2,5.5,5.5,5.7,5.7c0.2,0.2,0.6,0.3,1,0.3h0.6c0.2,0,0.4-0.2,0.4-0.4V2.4z M10,2C10,2,9.9,2.1,10,2
C9.9,2,10,2,10,2z"/>
<path class="skinthemeDark" d="M18.5,20.9c-0.1,0.1-0.2,0.1-0.4,0.1c-0.3,0-0.5-0.2-0.5-0.5c0-0.2,0.1-0.4,0.3-0.5l0,0
c3-1.5,5.1-4.5,5.1-8.1s-2.1-6.6-5.1-8.1l0,0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5c0.1,0,0.3,0.1,0.4,0.2
c3.3,1.6,5.5,5,5.5,8.9S21.8,19.3,18.5,20.9z M19,12c0,1.7-0.9,3.2-2.2,4.1c-0.1,0.1-0.2,0.2-0.4,0.2c-0.3,0-0.5-0.2-0.5-0.5
c0-0.2,0.1-0.4,0.3-0.5v0c1.1-0.7,1.8-1.9,1.8-3.3c0-1.4-0.7-2.6-1.8-3.3v0c-0.2-0.1-0.3-0.3-0.3-0.5c0-0.3,0.2-0.5,0.5-0.5
c0.2,0,0.3,0.1,0.4,0.2C18.1,8.8,19,10.3,19,12z"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

-80
View File
@@ -1,80 +0,0 @@
//这个函数在整个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
}
window.Application.PluginStorage.setItem("EnableFlag", false) //往PluginStorage中设置一个标记,用于控制两个按钮的置灰
window.Application.PluginStorage.setItem("ApiEventFlag", false) //往PluginStorage中设置一个标记,用于控制ApiEvent的按钮label
return true
}
var WebNotifycount = 0;
function OnAction(control) {
const eleId = control.Id
switch (eleId) {
case "btnShowMsg":
{
const doc = window.Application.ActiveDocument
if (!doc) {
alert("当前没有打开任何文档")
return
}
alert(doc.Name)
}
break;
default:
break
}
return true
}
function GetImage(control) {
const eleId = control.Id
switch (eleId) {
case "btnShowMsg":
return "images/1.svg"
default:
;
}
return "images/newFromTemp.svg"
}
function OnGetEnabled(control) {
const eleId = control.Id
switch (eleId) {
case "btnShowMsg":
return true
break
default:
break
}
return true
}
function OnGetVisible(control) {
return true
}
function OnGetLabel(control) {
const eleId = control.Id
switch (eleId) {
case "btnIsEnbable":
{
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
return bFlag ? "按钮Disable" : "按钮Enable"
break
}
}
return ""
}
function OnNewDocumentApiEvent(doc) {
alert("新建文件事件响应,取文件名: " + doc.Name)
}
+1 -1
View File
@@ -75,7 +75,7 @@ if __name__ == "__main__":
start_http_server() start_http_server()
# print(get_version()) # print(get_version())
path = r"c:\Users\32075\OneDrive\文档\Code\RPA_Script\wps-js-extension\XbotWps\python\wps.js" path = r"C:\Users\32075\OneDrive\文档\Code\RPA_Script\wps-js-extension\XbotWps\py-wps\wps.js"
with open(path, "r", encoding="utf8") as f: with open(path, "r", encoding="utf8") as f:
code = f.read() code = f.read()
View File
File renamed without changes.
-18
View File
@@ -1,18 +0,0 @@
# XbotWPS
## 介绍
## 功能
```
启动Word
Word导出PDF
读取Word文本
写入文本至Word中
定位Word光标
移动Word光标
替换Word文本
读取Word表格
插入Word表格, 插入图片, 插入超链接, 保存Word, 关闭Word
```
+213
View File
@@ -0,0 +1,213 @@
import os
import platform
import xml.dom.minidom as minidom
import sys
import shutil
import zipfile
def get_install_directory():
"""Get the correct installation directory based on the platform."""
system = platform.system()
if system == "Windows":
return os.path.join(os.environ.get("APPDATA"), "kingsoft", "wps", "jsaddons")
elif system == "Linux":
return os.path.join(
os.path.expanduser("~"), ".local", "share", "Kingsoft", "wps", "jsaddons"
)
else:
print(f"Unsupported platform: {system}")
sys.exit(1)
def create_authwebsite_xml(directory, node_name="xbotwps"):
"""Create the authwebsite.xml file if it doesn't exist or update it if it exists."""
file_path = os.path.join(directory, "authwebsite.xml")
# Create the basic XML structure if the file doesn't exist
if not os.path.exists(file_path):
# Create base XML structure
content = '<?xml version="1.0" encoding="UTF-8"?>\n<websites>\n</websites>\n'
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created basic authwebsite.xml structure at {file_path}")
try:
# Parse the XML file
dom = minidom.parse()
# Get the websites element
websites_elements = dom.getElementsByTagName("websites")
if not websites_elements:
# If no websites element exists, create it
websites = dom.createElement("websites")
dom.appendChild(websites)
else:
websites = websites_elements[0]
# Check if a website node with the specified name already exists
existing_nodes = []
for website in websites.getElementsByTagName("website"):
if website.getAttribute("name") == node_name:
existing_nodes.append(website)
# Remove existing nodes with the same name
for node in existing_nodes:
websites.removeChild(node)
# Create and append the new website node
new_website = dom.createElement("website")
new_website.setAttribute("origin", "null")
new_website.setAttribute("status", "enable")
new_website.setAttribute("name", node_name)
websites.appendChild(new_website)
# Save the updated XML file
with open(file_path, "w", encoding="utf-8") as f:
f.write(dom.toprettyxml(indent=" "))
print(f"Updated authwebsite.xml at {file_path}")
except Exception as e:
print(f"Error working with authwebsite.xml: {e}")
# Create a completely new file with the correct structure and node
content = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
"<websites>\n"
f' <website origin="null" status="enable" name="{node_name}"/>\n'
"</websites>\n"
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created new authwebsite.xml at {file_path}")
def create_publish_xml(
directory, node_name="xbotwps", addon_path=None, verson="1.0.0", addon_type="wps"
):
"""Create the publish.xml file if it doesn't exist or update it if it exists."""
file_path = os.path.join(directory, "publish.xml")
if addon_path is None:
raise ValueError("addon_path must be provided")
# Create the basic XML structure if the file doesn't exist
if not os.path.exists(file_path):
# Create base XML structure
content = '<?xml version="1.0" encoding="UTF-8"?>\n<jsplugins>\n</jsplugins>\n'
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created basic publish.xml structure at {file_path}")
try:
# Parse the XML file
dom = minidom.parse(file_path)
# Get the jsplugins element
jsplugins_elements = dom.getElementsByTagName("jsplugins")
if not jsplugins_elements:
# If no jsplugins element exists, create it
jsplugins = dom.createElement("jsplugins")
dom.appendChild(jsplugins)
else:
jsplugins = jsplugins_elements[0]
# Check if a jsplugin node with the specified name already exists
existing_nodes = []
for jsplugin in jsplugins.getElementsByTagName("jsplugin"):
if jsplugin.getAttribute("name") == node_name:
existing_nodes.append(jsplugin)
# Remove existing nodes with the same name
for node in existing_nodes:
jsplugins.removeChild(node)
# Create and append the new jsplugin node
new_jsplugin = dom.createElement("jsplugin")
new_jsplugin.setAttribute("enable", "enable_dev")
new_jsplugin.setAttribute("url", addon_path)
new_jsplugin.setAttribute("install", "null")
new_jsplugin.setAttribute("version", verson)
new_jsplugin.setAttribute("type", addon_type)
new_jsplugin.setAttribute("customDomain", "")
new_jsplugin.setAttribute("name", node_name)
jsplugins.appendChild(new_jsplugin)
# Save the updated XML file
with open(file_path, "w", encoding="utf-8") as f:
f.write(dom.toprettyxml(indent=" "))
print(f"Updated publish.xml at {file_path}")
except Exception as e:
print(f"Error working with publish.xml: {e}")
# Create a completely new file with the correct structure and node
content = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
"<jsplugins>\n"
f' <jsplugin enable="enable_dev" url="{addon_path}" install="null" version="1.0.0" type="wps" customDomain="" name="{node_name}"/>\n'
"</jsplugins>\n"
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created new publish.xml at {file_path}")
def extract_addon(addon_path, install_dir):
"""Extract the addon archive to the installation directory."""
addon_name = "xbotwps"
extract_dir = os.path.join(install_dir, addon_name)
# Clean the existing directory if it exists
if os.path.exists(extract_dir):
print(f"Removing existing addon directory: {extract_dir}")
shutil.rmtree(extract_dir)
# Create the extraction directory
os.makedirs(extract_dir)
# Determine the archive type and extract accordingly
file_ext = os.path.splitext(addon_path)[1].lower()
try:
print(f"Extracting ZIP archive to {extract_dir}")
with zipfile.ZipFile(addon_path, "r") as zip_ref:
zip_ref.extractall(install_dir)
print("Extraction completed successfully")
return True
except Exception as e:
print(f"Error extracting archive: {e}")
return False
def main():
# 1. 将插件文件解压到插件安装目录下
# 2. 从插件目录下读取package.json文件,获取插件名称, 版本号, 插件类型
# 3. 创建authwebsite.xml文件,添加插件名称节点
# 4. 创建publish.xml文件,添加插件名称节点
addon_path = r"C:\\Users\\32075\\OneDrive\\文档\\Code\\RPA_Script\\wps-js-extension\\XbotWps\\wps-addon-build\\xbotwps.zip"
node_name = "xbotwps"
install_dir = get_install_directory()
print(f"Installation directory: {install_dir}")
# Create the installation directory if it doesn't exist
if not os.path.exists(install_dir):
os.makedirs(install_dir)
print(f"Created installation directory: {install_dir}")
# Create the required XML files
create_authwebsite_xml(install_dir, node_name)
create_publish_xml(install_dir, node_name, addon_path)
# Extract the addon to the installation directory
if extract_addon(addon_path, install_dir):
print("Addon extracted successfully.")
else:
print("Failed to extract addon.")
print("Installation completed successfully.")
if __name__ == "__main__":
main()
+1
View File
@@ -0,0 +1 @@
# WPS 表格自动化
+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1743477113372" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1505" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 1024C229.376 1024 0 794.624 0 512S229.376 0 512 0s512 229.376 512 512-229.376 512-512 512z m0-949.248C271.36 74.752 75.776 271.36 75.776 512S271.36 949.248 512 949.248 949.248 752.64 949.248 512 752.64 74.752 512 74.752z m0 753.664a45.44 45.44 0 0 1-45.056-45.056V444.416c0-25.6 20.48-45.056 45.056-45.056s45.056 19.456 45.056 45.056V783.36A45.44 45.44 0 0 1 512 828.416z m0-474.112c-24.576 0-45.056-20.48-45.056-46.08V240.64c0-24.576 20.48-45.056 45.056-45.056s45.056 20.48 45.056 45.056v67.584c0 25.6-20.48 46.08-45.056 46.08z" p-id="1506"></path></svg>

After

Width:  |  Height:  |  Size: 893 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File
File renamed without changes.
+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"
}
View File
File renamed without changes.
+2
View File
@@ -1,5 +1,7 @@
let wpsInstance = null; let wpsInstance = null;
function InvokeFromXbot(param) { function InvokeFromXbot(param) {
// 1. 解析参数, 如果不是字符串, 则转换为字符串, 并用json解析, 解析失败直接retrun // 1. 解析参数, 如果不是字符串, 则转换为字符串, 并用json解析, 解析失败直接retrun
if (typeof param !== 'string') { if (typeof param !== 'string') {
View File
File renamed without changes.
+9
View File
@@ -0,0 +1,9 @@
{
"name": "xbotet",
"addonType": "et",
"version": "1.0.0",
"description": "借助插件实现WPS的自动化操作",
"devDependencies": {
"wps-jsapi-declare": "latest"
}
}
+12
View File
@@ -0,0 +1,12 @@
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnAddinLoad">
<ribbon startFromScratch="false">
<tabs>
<tab id="wpsAddinTab" label="影刀插件">
<group id="btnDemoGroup" label="group1">
<button id="btnShowAbout" label="关于" onAction="OnAction" getImage="GetImage"
visible="true" size="large" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
+1
View File
@@ -0,0 +1 @@
# WPS 文档自动化
+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1743477113372" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1505" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 1024C229.376 1024 0 794.624 0 512S229.376 0 512 0s512 229.376 512 512-229.376 512-512 512z m0-949.248C271.36 74.752 75.776 271.36 75.776 512S271.36 949.248 512 949.248 949.248 752.64 949.248 512 752.64 74.752 512 74.752z m0 753.664a45.44 45.44 0 0 1-45.056-45.056V444.416c0-25.6 20.48-45.056 45.056-45.056s45.056 19.456 45.056 45.056V783.36A45.44 45.44 0 0 1 512 828.416z m0-474.112c-24.576 0-45.056-20.48-45.056-46.08V240.64c0-24.576 20.48-45.056 45.056-45.056s45.056 20.48 45.056 45.056v67.584c0 25.6-20.48 46.08-45.056 46.08z" p-id="1506"></path></svg>

After

Width:  |  Height:  |  Size: 893 B

+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="21px" height="20px" viewBox="0 0 21 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 51.2 (57519) - http://www.bohemiancoding.com/sketch -->
<title>从模版新建</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Artboard" transform="translate(-31.000000, -26.000000)">
<g id="从模版新建" transform="translate(29.000000, 24.000000)">
<g id="Group" stroke-width="1">
<g id="新增节" transform="translate(2.000000, 2.000000)">
<path d="M19.9587402,10 L18.9587402,10 L18.9587402,2 C18.9587402,1.44771525 18.511025,1 17.9587402,1 L6.0300293,1 C5.47774455,1 5.0300293,1.44771525 5.0300293,2 L5.0300293,18 C5.0300293,18.5522847 5.47774455,19 6.0300293,19 L9.95874023,19 L9.95874023,20 L6.0300293,20 C4.9254598,20 4.0300293,19.1045695 4.0300293,18 L4.0300293,2 C4.0300293,0.8954305 4.9254598,2.02906125e-16 6.0300293,0 L17.9587402,0 C19.0633097,-2.02906125e-16 19.9587402,0.8954305 19.9587402,2 L19.9587402,10 Z" id="Combined-Shape" fill="#404040" fill-rule="nonzero"></path>
<path d="M6,1 L4,1 C3.44771525,1 3,1.44771525 3,2 L3,18 C3,18.5522847 3.44771525,19 4,19 L6,19 L6,20 L4,20 C2.8954305,20 2,19.1045695 2,18 L2,2 C2,0.8954305 2.8954305,2.02906125e-16 4,0 L6,0 L6,1 Z" id="Combined-Shape-Copy-2" fill="#404040" fill-rule="nonzero"></path>
<path d="M4,1 L2,1 C1.44771525,1 1,1.44771525 1,2 L1,18 C1,18.5522847 1.44771525,19 2,19 L4,19 L4,20 L2,20 C0.8954305,20 1.03797111e-16,19.1045695 0,18 L0,2 C-1.10284431e-16,0.8954305 0.8954305,2.02906125e-16 2,0 L4,0 L4,1 Z" id="Combined-Shape-Copy-3" fill="#404040" fill-rule="nonzero"></path>
<path d="M17,15 L20.5,15 C20.7761424,15 21,15.2238576 21,15.5 C21,15.7761424 20.7761424,16 20.5,16 L17,16 L17,19.5 C17,19.7761424 16.7761424,20 16.5,20 C16.2238576,20 16,19.7761424 16,19.5 L16,16 L12.5,16 C12.2238576,16 12,15.7761424 12,15.5 C12,15.2238576 12.2238576,15 12.5,15 L16,15 L16,11.5 C16,11.2238576 16.2238576,11 16.5,11 C16.7761424,11 17,11.2238576 17,11.5 L17,15 Z" id="Combined-Shape" fill="#5789D9"></path>
</g>
</g>
<rect id="Rectangle-15" fill="#404040" x="9" y="6" width="10" height="1"></rect>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

+6
View File
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script type="text/javascript" src="./main.js"></script>
</html>
<!--这个文件是wps加载项的入口文件,wps在启动时加载这个文件-->
+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};
}
}
+4
View File
@@ -0,0 +1,4 @@
//这个文件由index.html包含
document.write("<script language='javascript' src='js/util.js'></script>");
document.write("<script language='javascript' src='js/ribbon.js'></script>");
document.write("<script language='javascript' src='js/xbot.js'></script>");
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "xbotwps", "name": "xbotwps",
"addonType": "wps", "addonType": "wps",
"version": "1.0.0", "version": "1.0.0",
"description": "wps加载项示例, 执行npm install后,提供代码联想功能", "description": "借助插件实现WPS的自动化操作",
"devDependencies": { "devDependencies": {
"wps-jsapi-declare": "latest" "wps-jsapi-declare": "latest"
} }
+2 -1
View File
@@ -3,7 +3,8 @@
<tabs> <tabs>
<tab id="wpsAddinTab" label="XbotWPS"> <tab id="wpsAddinTab" label="XbotWPS">
<group id="btnDemoGroup" label="group1"> <group id="btnDemoGroup" label="group1">
<button id="btnShowMsg" label="添加文字" onAction="OnAction" getEnabled="OnGetEnabled" getImage="GetImage" visible="true" size="large"/> <button id="btnShowAbout" label="关于" onAction="OnAction" getImage="GetImage"
visible="true" size="large" />
</group> </group>
</tab> </tab>
</tabs> </tabs>