add readme
This commit is contained in:
1 parent
bd8a119506
commit
dd43fe06d9
2 files changed
+63
-3
No files matched your search
@@ -6,5 +6,16 @@
|
||||
|
||||
## 用法
|
||||
|
||||
```python
|
||||
import wps
|
||||
wps.run_app()
|
||||
wps.open('test.xlsx')
|
||||
wps.add_inline_picture()
|
||||
wps.close()
|
||||
wps.exit()
|
||||
```
|
||||
|
||||
|
||||
## 注意
|
||||
|
||||
- 必须使用模块启动 wps
|
||||
+52
-3
@@ -1,6 +1,10 @@
|
||||
import winreg
|
||||
import os
|
||||
import subprocess
|
||||
import base64
|
||||
import uuid
|
||||
import json
|
||||
import http.client
|
||||
|
||||
|
||||
def read_registry_value(key, subkey, value_name):
|
||||
@@ -30,7 +34,7 @@ def get_wps_exe_path():
|
||||
return wps_exe_path
|
||||
|
||||
|
||||
def run_wps():
|
||||
def run_app():
|
||||
"""启动 WPS"""
|
||||
wps_exe_path = get_wps_exe_path()
|
||||
params = ["/prometheus", "/t"]
|
||||
@@ -38,8 +42,53 @@ def run_wps():
|
||||
[wps_exe_path] + params,
|
||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS,
|
||||
)
|
||||
print("Process ID:", process.pid)
|
||||
|
||||
|
||||
def invoke_wps_func(func, args):
|
||||
# 可能触发是否允许访问
|
||||
invoke_param = {
|
||||
"Func": func,
|
||||
"Args": json.dumps(args),
|
||||
"AppType": "et",
|
||||
}
|
||||
|
||||
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": "et",
|
||||
"data": "ksowebstartupet://"
|
||||
+ 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)
|
||||
|
||||
response0 = conn.getresponse()
|
||||
data = response0.read()
|
||||
|
||||
conn.close()
|
||||
try:
|
||||
return json.loads(data.decode("utf-8"))
|
||||
except Exception as e:
|
||||
return {"message": "failed to parse response"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_wps()
|
||||
run_app()
|
||||
Reference in new issue
Block a user