Reformat to Template
Take a template (file 1) and a content file (file 2). Reshape file 2's
content so it follows file 1's format, table layout, and content requirements,
then save the result as a new file in the template's format.
When to use
- User uploads two files and says "把文件2按文件1的格式改一下 / 套用模板 /
改成模板的格式 / 转成表格形式 / 按这个模板排版". - User provides a template and asks to convert some content into that template's shape.
- Both files may be
.docx,.xlsx,.csv, or plain text — the output always
matches the template's format.
在模板中写「内容要求」(强烈推荐)
除了定格式,模板还能直接写明「内容要改成什么样」。这样即使文件 2 与模板字段不完全对应,skill 也能按你的指示做改写 / 抽取 / 汇总,而不只是机械填表。
两种写法都支持:
1. 显式标记块(最稳定),放在模板任意位置:
【要求】把文件2的口语化描述改写成第三人称客观叙述;成绩保留整数;缺失项填"无"。【/要求】
也支持 [[要求]]…[[/要求]] 或 <<<要求>>>…<<</要求>>>。
2. 带关键词的标题 + 其下段落:标题含「要求 / 说明 / 规范 / 改写 / 转换 / 注意」等词,下方段落即视为要求。例如一个标题「内容要求」下面写:「将文件2的要点提炼为每条不超过20字;按"问题—原因—对策"三栏组织。」
提取命令(模型会自动读取并作为改写依据):
"%PY%" scripts/docx_utils.py requirements "template.docx"
"%PY%" scripts/xlsx_utils.py requirements "template.xlsx"
若模板没有要求块,则仅按结构套用。
Environment setup
The bundled scripts need python-docx and openpyxl. Run them with the managed
Python venv that already has these installed:
PY="C:\Users\54183\.workbuddy\binaries\python\envs\default\Scripts\python.exe"
If a script fails to import, install once:
"%PY%" -m pip install python-docx openpyxl
(Adjust the venv path if the managed Python location differs on the user's machine.)
Workflow
1. Identify the two files
Confirm which upload is the template and which is the content. If the user
did not label them, ask which is the template before proceeding. Treat file 1 as
template unless told otherwise.
2. Inspect the template structure
Run the matching structure command and read its JSON output:
# Word template
"%PY%" scripts/docx_utils.py structure "template.docx"
# Excel / CSV template
"%PY%" scripts/xlsx_utils.py structure "template.xlsx"
"%PY%" scripts/xlsx_utils.py structure "template.csv"
Note the paragraph styles, detected {{placeholders}}, table indices + headers,
and sheet names. This JSON is the schema the content must fit into.
2.5 Extract the template's "内容要求" block (if any)
Run the requirements subcommand. If the output is not "(未检测到内容要求块)", treat
that text as the rewrite / extract / summarize instructions for file 2 and carry
them into later steps. These instructions take priority over generic inference —
e.g. "rewrite spoken text into objective third-person", "fill missing with 无",
"organize into three columns" must all be honored.
"%PY%" scripts/docx_utils.py requirements "template.docx"
"%PY%" scripts/xlsx_utils.py requirements "template.xlsx"
3. Read the content file
- If content is
.docx/.xlsx/.csv, use the matchingreadsubcommand
(docx_utils.py read/xlsx_utils.py read) or the structure command. - If content is
.txt/.md/.pdf, read it with the normal file-reading tools.
Extract the actual data points, records, and sections the template needs.
3.5 Detect content gaps and ask the user
After reading the content, compare it against everything the template and its
"内容要求" block actually require. Identify any required but missing parts, such as:
- a template section/heading (e.g. "下周计划") with no corresponding information in the content;
- a column or {{placeholder}} the template needs but the content cannot supply;
- a "内容要求" instruction expecting certain sub-items (e.g. "三栏:问题—原因—对策") where one is absent.
When gaps exist, do NOT silently fill them or skip them. Use AskUserQuestion to
confirm how to handle each gap. Batch up to 4 gaps into a single call (one question
per gap). For every gap offer these options:
1. 我自己补充 — the user will type the missing content next; wait for their input,
merge it into the content, then continue to mapping.
2. 由 AI 生成 — generate reasonable content from the template context and the
"内容要求" instructions; clearly mark AI-generated parts and ask the user to verify.
3. 留空 / 跳过 — leave the section blank or fill a neutral value (e.g. "无" / "待补充")
per the template or requirements, then continue.
Proceed to step 4 only after every gap is resolved (user input received, AI content
generated, or explicitly skipped).
4. Decide the mapping pattern
Map content → template using the patterns in references/format_patterns.md:
- Word placeholder template → placeholders map (模式 A)
- Word table template → tables map keyed by header text (模式 B)
- Word pure-structure template → rewrite section paragraphs on a template copy (模式 C)
- Excel column table → records keyed by header text per sheet (模式 D / E)
- Content requirements block present → follow its instructions for semantic
rewriting / extraction / summarization, then fit the result into the structure
(see references/usage_tips.md for examples).
Keep keys exactly equal to the template's placeholder text or header text
(spaces and punctuation included).
5. Build the output
For Word:
"%PY%" scripts/docx_utils.py fill "template.docx" "output.docx" --mapping mapping.json
mapping.json example:
{
"placeholders": { "title": "期中成绩表", "date": "2026-08-14" },
"tables": { "0": [ {"姓名": "Alice", "成绩": "90"}, {"姓名": "Bob", "成绩": "85"} ] }
}
For Excel / CSV:
"%PY%" scripts/xlsx_utils.py fill "template.xlsx" "output.xlsx" --mapping mapping.json
mapping.json example (xlsx, keyed by sheet):
{ "Sheet1": [ {"姓名": "Alice", "成绩": "90"}, {"姓名": "Bob", "成绩": "85"} ] }
For CSV the mapping is a top-level list of records. Generate mapping.json with
the Write tool, then run the fill command.
If the template is a pure-structure Word doc with no placeholders (模式 C), clone
the template and rewrite its paragraphs directly with python-docx (or have the
model produce the new section text and write it into the clone).
6. Validate and present
Re-run structure/read on the output and check:
- No leftover {{...}} placeholders.
- Table row count equals record count; columns line up with headers.
- Excel header row intact and not overwritten.
- Chinese renders without mojibake.
Then present the output file to the user via present_files.
Notes
- Never modify the user's original template or content files; always write a new output file.
- Record keys must match template headers/placeholders exactly.
- The "内容要求" block's instructions take priority over default inference; when they
conflict with the bare structure, follow the requirements. - When content is richer than the template, extra material should be summarized or
placed in an appropriate section rather than dropped silently — confirm with the
user if significant content would be omitted. - When content is thinner than the template (missing required sections/columns), the
gap MUST be surfaced to the user via AskUserQuestion before proceeding — never invent
or drop required content without confirmation. AI-generated fill-ins must be clearly
marked and offered for the user to verify.
使用提示(给使用者的速查)
- 最省事:直接给一个带
{{占位符}}或「表头+示例行」的模板,再给内容,说一句"按模板格式改"。 - 要指定改法:在模板里加一句要求,例如「【要求】把口语改成书面语;缺失填'无';每条不超过30字。【/要求】」,skill 会照做。
- 模板即内容:内容文件可以很乱(聊天记录、会议纪要、网页摘录),只要模板写清"要抽成什么结构",skill 会抽取重组。
- 格式以模板为准:无论内容是什么格式,输出都和模板同格式(docx→docx,xlsx→xlsx/csv)。
- 不确定哪个是模板:主动说明"文件1是模板",避免套反。
- 内容不够怎么办:若内容缺了模板要求的板块/列,skill 会弹窗问你——可自己补写、让 AI 生成,或留空跳过,不会擅自编造或丢弃。
- 更多示例见
references/usage_tips.md。