[](https://pypi.org/project/docx-parsing-gmdzy2010/)
### 功能概述
_________
本包基于一套自定义的`轻量级文本模板解析系统`,用于将文本文件转成Word的docx文件
#### 输入文件
###### 1. 文本模板文件
模板文件是一个纯文本文件,每3行为一个解析单位,解析规则只有以下3条:
>1.1 第一行包括元素类型和样式名称,用":"隔开;
>1.2 第二行为要写入docx文件的文本,每行内部分为多个run单位,用"||"隔开,每个run可以有下划线和加粗两种样式,在每个run的尾部,用"::"隔开
>1.3 第三行为分割线,79个下划线,为了让模板更易读而已,没太大意义
###### 2. DOCX模板文件
文件为一个空的或者自定义的docx文件,最好是包含python-docx自带docx模板的所有样式,方便直接调用
注意:样式有可能不生效,解决方法请移步python-docx的官方文档
###### 3. 文本模板的上下文数据
上下文数据为一个字典型的变量,用来对模板的变量进行格式化。
3.1 段落上下文对象`PARAGRAPH_CONTEXT`
例如,文本模板中有一个段落上下文变量`test_context`
```
...
cover:cover_title
模板内容||{test_context}::underline||后续文本
-------------------------------------------------------------------------------
...
```
则需要新建段落上下文对象,是一个python字典对象,可以以字典键值对的形式添加多个
```python
PARAGRAPH_CONTEXT = {
"demo_field_1": "测试文本",
"demo_field_2": 300.00,
"demo_field_3": 18003.00,
}
```
3.2 表格上下文对象`TABLE_CONTEXT`
例如,文本模板中有一个表格
```
...
table:demo_table_1
表格下面的文本不重要,仅仅用于占位
-------------------------------------------------------------------------------
...
```
这时需要新建表格上下文对象,包含表格的维度`rows`, `cols`,样式`style`等,类似于下方,可以以字典键值对的形式添加多个
```python
TABLE_CONTEXT = {
"demo_table_1": {
"attr": {
"style": "Table Grid",
"rows": 5,
"cols": 4,
},
"data": (
("第1列标题", "第2列标题", "第3列标题", "第4列标题"),
("第1行第1列内容", "第1行第2列内容", "第1行第3列内容", "第1行第4列内容"),
("第2行第1列内容", "第2行第2列内容", "第2行第3列内容", "第2行第4列内容"),
("第3行第1列内容", "第3行第2列内容", "第3行第3列内容", "第3行第4列内容"),
("第4行第1列内容", "第4行第2列内容", "第4行第3列内容", "第4行第4列内容"),
)
},
},
```
3.3 图片上下文对象`PICTURE_CONTEXT`
仍在测试中,后续单元测试通过后会将文档更新
### 使用
_________
>STEP 1. 在项目中导入渲染器`DocxProduce`,
>STEP 2. 写好文本模板,选择一个自带样式比较齐全的DOCX文件,可以从python-docx默认的模板拷贝而来
>STEP 3. 加载准备好的上下文和格式及样式数据,执行程序即完成
Metadata
Release files for docx-parsing-gmdzy2010 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docx_parsing_gmdzy2010-1.2.1.tar.gz | 7.2 kB | Without provenance | Details for docx_parsing_gmdzy2010-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docx_parsing_gmdzy2010-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for docx_parsing_gmdzy2010-1.2.1-py3-none-any.whl |
Total release size: 17.9 kB
Release files / docx_parsing_gmdzy2010-1.2.1.tar.gz
| Download URL | docx_parsing_gmdzy2010-1.2.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5965b8bd8b70272a16ce2ab14d8123cd8b17412186cbde2ac18c51e23facdac
|
|
BLAKE2b-256 checksum How to use checksums |
a0cbd82aabffd4f392929f7fc86494eac689df6ec004a39a9b6a07edc5cd508b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.12.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.0
|
Release files / docx_parsing_gmdzy2010-1.2.1-py3-none-any.whl
| Download URL | docx_parsing_gmdzy2010-1.2.1-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59f4df3bea8b8b024fcb0186da4bd1fbe0b1f1900bc2eebde55cd2274f1d4609
|
|
BLAKE2b-256 checksum How to use checksums |
d92defdd8bac764ef4de38bb4bfd7b5b97183059cac4dbe028f56a429f242631
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.12.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.0
|
Security for docx-parsing-gmdzy2010 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.