diff --git a/.gitignore b/.gitignore index d017762..63dadd9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ /build/ /dist/ .idea -*.spec \ No newline at end of file +*.spec +.venv +*.docx +!template.docx \ No newline at end of file diff --git a/data.json b/data.json index 725e0db..7a6c0ca 100644 --- a/data.json +++ b/data.json @@ -26,12 +26,12 @@ }, { "key": "{Test1}", - "value": "2025年11月26日", + "value": "2TEst1打赏", "type": "text" }, { "key": "{Test2}", - "value": "2025年11月26日", + "value": "20TEst2打赏萨格", "type": "text" }, { diff --git a/demo.docx b/demo.docx deleted file mode 100644 index 6c2d1cb..0000000 Binary files a/demo.docx and /dev/null differ diff --git a/main.py b/main.py index 94075d9..ca24ab6 100644 --- a/main.py +++ b/main.py @@ -119,10 +119,11 @@ def replace(template_path, filename_path, data_json): repeat = True else: for paragraph in cell.paragraphs: + paragraph.text = paragraph.text.replace(" ", "") for run in paragraph.runs: find = False for datum in data_json: - if datum["key"] in cell.text: + if datum["key"] in run.text: find = True if "text" == datum["type"]: run.text = run.text.replace(datum["key"], datum["value"]) diff --git a/template.docx b/template.docx index 333017d..19586f1 100644 Binary files a/template.docx and b/template.docx differ