Skip to main content

Docx Cleaner

一键清理 AI 生成文档粘贴到 Word 后的格式乱象。

痛点

AI(如 ChatGPT、Claude、DeepSeek 等)生成的文字内容直接复制粘贴到 Word 中,常出现以下格式问题:

问题 示例
公式运算符周围多空格 P = 500 × 1.276 = 638
中文与数字/标点间多空格 95.5 人月、440675 元
列表缩进用空格 第1年: 还本金5万
中文与英文术语间多空格 功能点 UFP → 功能点UFP

这些问题手动修复耗时且容易遗漏,本工具一键处理。

功能

  • 公式空格清理:去除 =, ×, +, -, / 等运算符周围多余空格
  • 中文间距清理:去除中文与数字、标点、英文之间的多余空格
  • 全量空格清理:去除所有非英文字母分隔的空格(保留 Unit Testing 这类英文单词间距)
  • 缩进转换:将行首空格统一转换为制表符 \t(可选)
  • 原地/新文件输出:支持覆盖原文件或另存为新文件

安装

pip install docx-cleaner

或直接从源码使用:

git clone https://github.com/WUIR/docx-cleaner.git
cd docx-cleaner
pip install .

快速开始

# 清理单个文件(覆盖原文件)
docx-cleaner input.docx

# 清理后另存为新文件
docx-cleaner input.docx -o output.docx

# 全部清理 + 空格转制表符
docx-cleaner input.docx --tab

# 只做公式和中文间距清理(保留其他空格)
docx-cleaner input.docx --light

命令行选项

usage: docx-cleaner [-h] [-o OUTPUT] [--tab] [--light] input

positional arguments:
  input                 输入的 .docx 文件路径

options:
  -h, --help            显示帮助信息
  -o, --output OUTPUT   输出文件路径(默认覆盖原文件)
  --tab                 将行首空格缩进替换为制表符
  --light               轻量模式:只做公式和中文间距清理

Python API

from docx_cleaner import clean

# 打开文件 -> 清理 -> 保存
clean("report.docx")                     # 覆盖原文件
clean("report.docx", output="clean.docx") # 另存新文件
clean("report.docx", tab=True)            # 行首空格转制表符
clean("report.docx", light=True)          # 轻量模式

处理流程

输入 .docx
    ↓
解压 ZIP (OOXML)
    ↓
1️⃣ 公式运算符空格清理   P = 25 × 3  →  P=25×3
    ↓
2️⃣ 中文与非中文间距清理  95.5 人月  →  95.5人月
    ↓
3️⃣ 全量字符空格清理      , i=5.0%  →  ,i=5.0%
    ↓
4️⃣ [可选] 缩进空格→制表符  2空格缩进 → \t
    ↓
压缩回 .docx
    ↓
输出文件

开源协议

MIT License

作者

Desola · 1817881032@qq.com

贡献

欢迎提交 Issue 和 PR!如果你遇到新的格式问题,欢迎反馈。

Metadata

Release files for docx-cleaner 0.1.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-cleaner 0.1.0
File Size Uploaded Provenance Actions
docx_cleaner-0.1.0.tar.gz 7.3 kB Without provenance Details for docx_cleaner-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docx-cleaner 0.1.0
File Interpreter ABI Platform Actions
docx_cleaner-0.1.0-py3-none-any.whl Python 3 none any Details for docx_cleaner-0.1.0-py3-none-any.whl

Total release size: 16.7 kB

Release files / docx_cleaner-0.1.0.tar.gz

Download URL docx_cleaner-0.1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9e5da9bc0621e7372620a665e511d0cc15ea03fcef82952e8b6ec0859eba0e41
BLAKE2b-256 checksum
How to use checksums
cb8aac5511417e519a771c10a5a87ed061639bb7dbe366ead9c048d2ba8a4511
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / docx_cleaner-0.1.0-py3-none-any.whl

Download URL docx_cleaner-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab477f2661f94e93d95706558e58d957ac1321f4faf3121199485c93310b3f35
BLAKE2b-256 checksum
How to use checksums
e86182d463199171d9f3a672a5dc8e4c6c3e25443548d2703f5529b9f3cd884c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for docx-cleaner 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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