Skip to main content
# 文本模板转DOCX文件
[![PyPI](https://img.shields.io/pypi/v/docx-parsing-gmdzy2010.svg)](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. 写好


Metadata

Release files for docx-parsing-gmdzy2010 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docx-parsing-gmdzy2010 1.2.0
File Size Uploaded Provenance Actions
docx_parsing_gmdzy2010-1.2.0.tar.gz 6.7 kB Without provenance Details for docx_parsing_gmdzy2010-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docx-parsing-gmdzy2010 1.2.0
File Interpreter ABI Platform Actions
docx_parsing_gmdzy2010-1.2.0-py3-none-any.whl Python 3 none any Details for docx_parsing_gmdzy2010-1.2.0-py3-none-any.whl

Total release size: 16.9 kB

Release files / docx_parsing_gmdzy2010-1.2.0.tar.gz

Download URL docx_parsing_gmdzy2010-1.2.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2ae403e56b9422359c2a31ddafb2ad7260c05523b0307578ce96ebb5df273f0f
BLAKE2b-256 checksum
How to use checksums
8221bcdf9067e9f9f248cb8cb84be01eab4f3dd24ae62daa8bd2a8c9547196d8
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.0-py3-none-any.whl

Download URL docx_parsing_gmdzy2010-1.2.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2785a7b1073ef3637448cdac8504699b9d1766e2e1f43208f00d62dc0bd33cf6
BLAKE2b-256 checksum
How to use checksums
c890e82526904b91910f84d5ac259ea74462867a9426a0b535a4d295b7ef514d
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.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page