UiAuto|Word插件

关于word的插件其实有很多种使用需求,该篇博文后续会根据实际使用情况再更新。
本次是需要对一篇word的内容进行检索,判断是否涉及某个字符串,代码比较简单,插件源码如下:

package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
"id": "zjtWord",
"name": "zjtword",
"description": "word文档内容查询,检索是否存在某关键字符串",
"version": "1.0.0",
"author": "chendi",
"language": "python",
"license": "Official",
"main": "index.py",
"uiauto_config": {
"attribution_id": "file_operation",
"attribution_name": "文件处理",
"operations": [
{
"category_id": "word",
"category_name": "WORD",
"operation_id": "searchWord",
"operation_name": "word内容判断",
"method": "searchWord",
"type": "Convention",
"input": [
{
"name": "必填属性",
"id": "required_params",
"properties": [
{
"id": "filePath",
"name": "文件路径",
"type": "path",
"required": true,
"value": "",
"options":{
"select_type":"openDirectory"
}
},
{
"id": "fileName",
"name": "文件名(xxx.docx)",
"type": "text",
"required": true,
"value": ""
},
{
"id": "keyword",
"name": "检索内容",
"type": "text",
"required": true,
"value": ""
}
]
}
],
"output": {
"is_allow_global_use": true,
"description": "文件处理结果",
"value": "isExist"
}
}
]
}
}

index.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- encoding:utf-8 -*-
'''
@description: 基于docx,处理word文档
@Time : 2023-06-02
@Author : CHENDI
@Version : 1.0.0
@Contact : henanchendi@163.com
'''
from docx import Document

# 根据关键字检索word内容
def searchWord(params):
# 获取参数
filePath = params.get('filePath')
fileName = params.get('fileName')
keyword = params.get('keyword')

path = '{}\\{}'.format(filePath,fileName)
isExist = False
doc = Document(path)
for paragraph in doc.paragraphs:
if keyword in paragraph.text:
isExist = True
break
return isExist


if __name__ == '__main__':
pass


商业转载请联系作者获得授权,非商业转载请注明出处。

支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

UiAuto|Word插件
http://hncd1024.github.io/2023/06/02/UiAuto_word/
作者
CHEN DI
发布于
2023-06-02
许可协议