Skip to content

Repository files navigation

AI Word 模板填充与生成工具

🎯 专为 Aspose 系模板引擎设计 / Built for Aspose-style template engines

本工具是 Aspose.Words / Aspose 系模板引擎 的配套制作与填充助手:模板控制语法(foreach / if / indexOf() / cellMerge)完全对齐 Aspose 风格模板标记,AI 自动识别可变字段生成模板、按数据批量填充,生成的 .docx 可直接交给 Aspose 环境渲染。

This tool is a companion authoring & filling assistant for Aspose.Words and Aspose-style template engines. Its control syntax (foreach / if / indexOf() / cellMerge) matches Aspose-style template markers; AI detects variable fields to build templates and fills them from data. Generated .docx templates are directly usable in Aspose environments.

一个基于 AI(DeepSeek,OpenAI 兼容接口)的 Word 文档处理 Web 工具:上传模板,AI 自动识别可变字段、填充内容、按模板语法生成表格行 / 段落,保留 Word 原生格式。

A web tool that uses AI (DeepSeek, OpenAI-compatible API) to process Word documents: upload a template, let AI detect variable fields, fill in content, and repeat table rows / paragraphs based on template control syntax — all while preserving the native Word formatting.


功能特性 / Features

模式 Mode 说明 Description
template 模板制作 上传原始 Word,AI 识别可变字段并替换成占位符,返回可复用模板
fill 模板填充 上传带占位符的 Word 当格式模板,AI 填充内容,保留原生格式
ai AI 生成 按描述生成新文档,参考 Word 仅提供样式
clone 原样克隆 直接复制上传 Word
md Markdown 转 Word 上传 .md 或粘贴 Markdown 内容,渲染成格式化的 Word 文档

Markdown 转 Word(md 模式)/ Markdown to Word (md mode)

上传 .md / .markdown / .txt 文件,或直接粘贴 Markdown 文本,即可渲染为格式化的 Word 文档(无需 AI、无需 API Key)。支持:标题 # ~ ######、表格、代码块、引用、有序 / 无序列表、分隔线、加粗、斜体、行内代码、链接。

Upload a .md / .markdown / .txt file, or paste Markdown text directly, and it will be rendered into a formatted Word document (no AI or API key needed). Supported: headings # ~ ######, tables, code blocks, blockquotes, ordered / unordered lists, horizontal rules, bold, italic, inline code, and links.

中英文切换与易用性 / Localization & Accessibility

界面支持 中文 / English 一键切换(右上角「EN / 中文」按钮),语言偏好自动记忆,下次打开自动恢复。

The UI supports one-click Chinese / English switching (the "EN / 中文" button in the top-right corner). Your language preference is saved automatically and restored the next time you open the page.

  • 无障碍使用:无需注册账号、无需复杂配置,纯本地运行,打开即用;表单采用原生控件并带有清晰的键盘焦点样式,鼠标、键盘均可顺畅操作,文件支持拖拽上传与点击选择两种方式。
  • Accessible by default: no account or complex setup required — it runs locally and is ready to use. Native form controls with clear keyboard focus styles work smoothly with mouse or keyboard, and files can be added by drag-and-drop or click-to-select.

模板填充语法(fill 模式)/ Template syntax (fill mode)

引擎支持类似 FreeMarker 的模板控制语法,不绑定任何特定模板,任何按此语法书写的 .docx 均可使用。该语法面向 Aspose 系模板引擎(foreach / if / indexOf() / cellMerge 等控制标记),本工具用于辅助制作与填充此类模板。

The engine supports FreeMarker-like control syntax. It is template-agnostic — any .docx written with this syntax works. The syntax targets Aspose-style template engines (control markers such as foreach / if / indexOf() / cellMerge); this tool helps you author and fill such templates.

写法 Syntax 含义 Meaning
<<[xxx()]>> 普通字段,AI 填值 / Plain field, filled by AI
<<foreach[Type var in xxx()]>> ... <</foreach>> 循环复制表格行 / 段落 Repeat table rows / paragraphs
<<if[xxx() != null]>> ... <</if>> 条件,为假删行 / 删段 Conditional, removes row / paragraph when false
<<[indexOf() + 1]>> 循环行号 Row number in a loop
<<cellMerge>> 单元格合并标记,安全移除 Merge marker, safely removed

界面截图 / Screenshots

首页 · 中文界面 / Homepage (Chinese UI)

首页中文

首页 · English UI

首页英文

模板生成前 / Before template generation

生成前的demo

生成后 / After generation

生成后的demo


快速开始 / Quick Start

1. 环境要求 / Requirements

  • Python 3.8+
  • (可选 / Optional)LibreOffice 或 Microsoft Word —— 用于 .doc.docx 转换;没有时请将文件另存为 .docx

2. 安装依赖 / Install dependencies

pip install -r requirements.txt

3. 配置 API Key / Configure API Key

通过环境变量设置(推荐),或直接在页面输入框填写:

Set via environment variable (recommended), or fill it directly in the web page:

# Linux / macOS
export DEEPSEEK_API_KEY="sk-xxxx"

# Windows PowerShell
$env:DEEPSEEK_API_KEY = "sk-xxxx"

可选配置 / Optional config:

环境变量 Env var 默认值 Default 说明 Description
DEEPSEEK_API_KEY 空 Empty DeepSeek API 密钥 API key
DEEPSEEK_MODEL deepseek-v4-flash 模型名称 Model name
DEEPSEEK_BASE_URL https://api.deepseek.com/v1 API 地址(OpenAI 兼容)API base URL

4. 启动 / Run

python app.py

打开浏览器访问 http://127.0.0.1:5000

Open your browser and visit http://127.0.0.1:5000.

命令行使用(可选)/ CLI usage (optional)

# AI 生成文档:根据描述生成 Word 文档
python gen_with_ai.py -d "生成一份培训班结业证书" -k sk-xxxx -o output.docx

# 参数 / Args: -d 描述 / description, -k API key, -o 输出 / output, --model 模型, --base-url API 地址

项目结构 / Project Structure

wordsmith/
├── app.py                # Flask 路由入口 / Flask web entry
├── services.py           # 业务编排(多模式分发)/ Business orchestration
├── config.py             # 配置(环境变量)/ Config (env vars)
├── gen_with_ai.py        # CLI:AI 生成文档 / CLI: AI document generation
├── generate_word.py      # 渲染 docx 核心逻辑 / docx rendering core
├── requirements.txt
├── prompts/
│   └── AI提示词.txt      # AI 系统提示词 / AI system prompt
├── ai/
│   ├── client.py         # DeepSeek API 客户端 / API client
│   └── prompts.py        # 提示词构建 / Prompt builders
├── core/
│   ├── render.py         # 纯文本 -> docx 渲染 / text-to-docx renderer
│   ├── markdown_render.py# Markdown -> docx 渲染 / Markdown-to-docx renderer
│   ├── filler.py         # 占位符替换 / placeholder filling
│   ├── foreach.py        # foreach/if/indexOf 结构引擎 / control syntax engine
│   ├── convert.py        # .doc <-> .docx 转换 / format conversion
│   ├── docx_utils.py     # docx 工具函数 / docx utilities
│   └── styles.py         # 样式处理 / style handling
├── templates/index.html  # Web 前端页面 / Web UI
├── static/               # 前端资源 / frontend assets
├── README.MD
└── LICENSE

注意事项 / Notes

  • 引擎按 .docx(python-docx 可读格式)工作。WordML(Word 2003 XML)格式无法读取,请先在 Word 中「另存为 .docx」再上传。

  • .doc(Word 97-2003 二进制格式)自动转换需要本机安装 LibreOffice 或 Microsoft Word。

  • 请勿将真实 API Key 写入 config.py 或提交到代码仓库,请通过环境变量提供。

  • The engine works with .docx (python-docx readable). WordML (Word 2003 XML) cannot be parsed — please "Save As .docx" in Word before uploading.

  • .doc (Word 97-2003 binary) auto-conversion requires LibreOffice or Microsoft Word installed locally.

  • Do NOT put a real API key into config.py or commit it to the repository — use environment variables instead.


许可证 / License

MIT

About

AI Word templating tool for Aspose-style templates: AI detects fields, fills content, repeats rows via foreach/if/cellMerge, keeps formatting. / 面向Aspose模板的AI Word填充生成工具。

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages