first commit
This commit is contained in:
1 parent
5b00bd10d0
commit
d15e8185bb
14 files changed
+203
-371
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# XbotWPS
|
||||
|
||||
## 介绍
|
||||
|
||||
|
||||
## 功能
|
||||
|
||||
```
|
||||
启动Word
|
||||
Word导出PDF
|
||||
读取Word文本
|
||||
写入文本至Word中
|
||||
定位Word光标
|
||||
移动Word光标
|
||||
替换Word文本
|
||||
读取Word表格
|
||||
插入Word表格, 插入图片, 插入超链接, 保存Word, 关闭Word
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
import base64
|
||||
import uuid
|
||||
import json
|
||||
import http.client
|
||||
import webbrowser
|
||||
|
||||
|
||||
def start_http_server():
|
||||
"""start debug"""
|
||||
webbrowser.open("ksowpscloudsvr://start=RelayHttpServer")
|
||||
|
||||
|
||||
def get_version():
|
||||
"""check http status by get version"""
|
||||
try:
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 58890)
|
||||
conn.request("POST", "/version", body="{}", headers={})
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
conn.close()
|
||||
return response.status == 200
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
def invoke_wps_func(func, args):
|
||||
|
||||
# 可能触发是否允许访问
|
||||
invoke_param = {
|
||||
"Func": func,
|
||||
"Args": json.dumps(args),
|
||||
"AppType": "wps",
|
||||
}
|
||||
|
||||
req_uui = str(uuid.uuid4())
|
||||
|
||||
info = f"{json.dumps(invoke_param)});\
|
||||
var xhr = new XMLHttpRequest();\
|
||||
xhr.open('POST', 'http://127.0.0.1:58890/transferEcho/runParams');\
|
||||
xhr.send(JSON.stringify({{id: '{req_uui}', response: res}}));void(0"
|
||||
|
||||
data = {
|
||||
"name": "xbotwps",
|
||||
"function": "var res = InvokeFromXbot",
|
||||
"info": info,
|
||||
"showToFront": True,
|
||||
"jsPluginsXml": "",
|
||||
}
|
||||
|
||||
payload = {
|
||||
"id": req_uui,
|
||||
"app": "wps",
|
||||
"data": "ksowebstartupwps://"
|
||||
+ base64.b64encode(json.dumps(data).encode()).decode(),
|
||||
"mode": False,
|
||||
}
|
||||
|
||||
conn = http.client.HTTPConnection("127.0.0.1", 58890)
|
||||
payload = json.dumps(payload)
|
||||
|
||||
conn.request("POST", "/transfer/runParams", payload)
|
||||
|
||||
http_response = conn.getresponse()
|
||||
data = http_response.read()
|
||||
conn.close()
|
||||
|
||||
try:
|
||||
return json.loads(data.decode("utf-8"))
|
||||
except Exception as e:
|
||||
print(data.decode("utf-8"))
|
||||
return {"message": "failed to parse response"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start_http_server()
|
||||
|
||||
print(get_version())
|
||||
|
||||
func = "getDocumentName"
|
||||
func = "evalCode"
|
||||
args = {"code": "wps.WpsApplication().ActiveDocument.Name"}
|
||||
res = invoke_wps_func(func, args)
|
||||
print(res)
|
||||
@@ -0,0 +1,29 @@
|
||||
const wps = {
|
||||
app: wps.WpsApplication(),
|
||||
replace: () => {
|
||||
Selection.SetRange(16, 16);
|
||||
Selection.Find.Wrap = wdFindContinue;
|
||||
(obj => {
|
||||
obj.Text = "1";
|
||||
obj.Forward = true;
|
||||
obj.Wrap = wdFindContinue;
|
||||
obj.MatchCase = false;
|
||||
obj.MatchByte = true;
|
||||
obj.MatchWildcards = false;
|
||||
obj.MatchWholeWord = false;
|
||||
obj.MatchFuzzy = false;
|
||||
obj.Replacement.Text = "2";
|
||||
})(Selection.Find);
|
||||
(obj => {
|
||||
obj.Style = "";
|
||||
obj.Highlight = wdUndefined;
|
||||
(obj => {
|
||||
obj.Style = "";
|
||||
obj.Highlight = wdUndefined;
|
||||
})(obj.Replacement);
|
||||
})(Selection.Find);
|
||||
Selection.Find.Execute(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, wdReplaceAll, undefined, undefined, undefined, undefined);
|
||||
Selection.Find.Replacement.Text = "2";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user