Skip to content
项目
群组
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
统计
统计docx文档信息
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
静态页
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
系统群组
开源项目
统计docx文档信息
提交
6cf7c8a7
提交
6cf7c8a7
9月 05, 2022
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace statistics.py
上级
0dbe8ce2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
28 行删除
+33
-28
statistics.py
statistics.py
+33
-28
没有找到文件。
statistics.py
浏览文件 @
6cf7c8a7
#python3
import
odf
import
sys
import
docx
import
os
,
zipfile
,
xml
.
dom
.
minidom
,
sys
,
getopt
import
requests
,
json
from
odf.namespaces
import
TEXTNS
from
odf.element
import
Element
from
odf.opendocument
import
load
from
odf
import
text
,
meta
,
office
,
draw
# 加载报告文件
doc
=
load
(
sys
.
argv
[
1
])
# 页数、字符数、表格数、图片数
page_count
=
0
character_count
=
0
table_count
=
0
image_count
=
0
# API路径
api_url
=
sys
.
argv
[
2
]
+
"/api/v4/labreportstatistics?"
+
sys
.
argv
[
4
]
+
"="
+
sys
.
argv
[
5
]
# 项目id
...
...
@@ -16,32 +16,37 @@ project_id = sys.argv[3]
# ci_job_token
token
=
sys
.
argv
[
4
]
# 将需要的报告统计参数保存
for
stat
in
doc
.
getElementsByType
(
meta
.
DocumentStatistic
):
# 取得报告页数、字数、表格数、图片数信息
page_count
=
stat
.
getAttribute
(
'pagecount'
)
word_count
=
stat
.
getAttribute
(
'wordcount'
)
table_count
=
stat
.
getAttribute
(
'tablecount'
)
image_count
=
stat
.
getAttribute
(
'imagecount'
)
# 还可以统计出报告中的以下内容
# stat.getAttribute('cellcount')
# 汉字或字符数量(含空格)stat.getAttribute('charactercount')
# stat.getAttribute('drawcount')
# stat.getAttribute('framecount')
# 汉字或字符数量(不含空格)stat.getAttribute('nonwhitespacecharactercount')
# stat.getAttribute('objectcount')
# 链接数量stat.getAttribute('oleobjectcount')
# 段落数量stat.getAttribute('paragraphcount')
# stat.getAttribute('rowcount')
# 句子数量stat.getAttribute('sentencecount')
# stat.getAttribute('syllablecount')
# 取得docx文档的页数、字数和字符数的数据
document
=
zipfile
.
ZipFile
(
sys
.
argv
[
1
])
dxm1
=
document
.
read
(
'docProps/app.xml'
)
uglyxml
=
xml
.
dom
.
minidom
.
parseString
(
dxm1
)
page_count
=
uglyxml
.
getElementsByTagName
(
'Pages'
)[
0
]
.
childNodes
[
0
]
.
nodeValue
# 这个字符数将一个汉字做为一个字符,将一个字母做为一个字符
# 先取Characters如果没有,就用CharactersWithSpaces
# 测试时如果用libreoffice打开docx文件后保存,选择”Use Microsoft Word 2007-2013 XML Format“后,图片可以正常统计数量,但是app.xml文件中只有CharactersWithSpaces参数,没有Characters参数
find_character
=
uglyxml
.
getElementsByTagName
(
'Characters'
)
if
not
find_character
:
character_count
=
uglyxml
.
getElementsByTagName
(
'CharactersWithSpaces'
)[
0
]
.
childNodes
[
0
]
.
nodeValue
else
:
character_count
=
find_character
[
0
]
.
childNodes
[
0
]
.
nodeValue
# 取得docx文档的表格数
mydocx
=
docx
.
Document
(
sys
.
argv
[
1
])
table_count
=
len
(
mydocx
.
tables
)
# 取得docx文档的图片数
# 通过调试查看target_ref,发现图片在文档中会设置一个形如imageX的默认名
dict_rel
=
mydocx
.
part
.
_rels
for
rel
in
dict_rel
:
rel_info
=
dict_rel
[
rel
]
if
"image"
in
rel_info
.
target_ref
:
image_count
+=
1
# 准备向接口发送的参数
data
=
{
'project_id'
:
project_id
,
'page_count'
:
page_count
,
'word_count'
:
word
_count
,
'word_count'
:
character
_count
,
'table_count'
:
table_count
,
'image_count'
:
image_count
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论