首页/AI 工程/template-engine
T

template-engine

by @claude-office-skillsv1.0.0
4.5(5)

基于模板的文档生成引擎,支持自定义模板和变量替换

templateengineaillmagentsGitHub
安装方式
npx skills add claude-office-skills/skills --skill template-engine
compare_arrows

Before / After 效果对比

1
使用前

手动完成基于模板的文档生成引擎,支持自相关任务,需要反复查阅文档和调试,整个过程大约需要117分钟,容易出错且效率低下

使用后

使用该 Skill 自动化处理,8分钟内完成全部工作,流程标准化且准确率高

description SKILL.md

template-engine

Template Engine Skill

Overview

This skill enables template-based document generation - define templates with placeholders, then automatically fill them with data. Works with Word, Excel, PowerPoint, and more.

How to Use

  • Describe what you want to accomplish

  • Provide any required input data or files

  • I'll execute the appropriate operations

Example prompts:

  • "Mail merge for bulk letters/contracts"

  • "Generate personalized reports from data"

  • "Create certificates from templates"

  • "Auto-fill forms with user data"

Domain Knowledge

Template Syntax (Jinja2-based)

{{ variable }}           - Simple substitution
{% for item in list %}   - Loop
{% if condition %}       - Conditional
{{ date | format_date }} - Filter

Word Template Example

from docxtpl import DocxTemplate

# Create template with placeholders:
# Dear {{ name }},
# Thank you for your order #{{ order_id }}...

def fill_template(template_path: str, data: dict, output_path: str):
    doc = DocxTemplate(template_path)
    doc.render(data)
    doc.save(output_path)
    return output_path

# Usage
fill_template(
    "templates/order_confirmation.docx",
    {
        "name": "John Smith",
        "order_id": "ORD-12345",
        "items": [
            {"name": "Product A", "qty": 2, "price": 29.99},
            {"name": "Product B", "qty": 1, "price": 49.99}
        ],
        "total": 109.97
    },
    "output/confirmation_john.docx"
)

Excel Template

from openpyxl import load_workbook
import re

def fill_excel_template(template_path: str, data: dict, output_path: str):
    wb = load_workbook(template_path)
    ws = wb.active
    
    # Find and replace placeholders like {{name}}
    for row in ws.iter_rows():
        for cell in row:
            if cell.value and isinstance(cell.value, str):
                for key, value in data.items():
                    placeholder = "{{" + key + "}}"
                    if placeholder in cell.value:
                        cell.value = cell.value.replace(placeholder, str(value))
    
    wb.save(output_path)
    return output_path

Bulk Generation (Mail Merge)

import csv
from pathlib import Path

def mail_merge(template_path: str, data_csv: str, output_dir: str):
    """Generate documents for each row in CSV."""
    
    Path(output_dir).mkdir(exist_ok=True)
    
    with open(data_csv) as f:
        reader = csv.DictReader(f)
        
        for i, row in enumerate(reader):
            output_path = f"{output_dir}/document_{i+1}.docx"
            fill_template(template_path, row, output_path)
            print(f"Generated: {output_path}")

# Usage with contacts.csv:
# name,email,company
# John,john@example.com,Acme
# Jane,jane@example.com,Corp

mail_merge(
    "templates/welcome_letter.docx",
    "data/contacts.csv",
    "output/letters"
)

Advanced: Conditional Content

from docxtpl import DocxTemplate

# Template with conditionals:
# {% if vip %}
# Thank you for being a VIP member!
# {% else %}
# Thank you for your purchase.
# {% endif %}

doc = DocxTemplate("template.docx")
doc.render({
    "name": "John",
    "vip": True,
    "discount": 20
})
doc.save("output.docx")

Best Practices

  • Use clear placeholder naming ({{client_name}})

  • Validate data before rendering

  • Handle missing data gracefully

  • Keep templates version-controlled

Installation

# Install required dependencies
pip install python-docx openpyxl python-pptx reportlab jinja2

Resources

Weekly Installs266Repositoryclaude-office-s…s/skillsGitHub Stars26First SeenMar 9, 2026Security AuditsGen Agent Trust HubPassSocketPassSnykPassInstalled onclaude-code217opencode112github-copilot111kimi-cli109gemini-cli109amp109

forum用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价,来写第一条吧

统计数据

安装量200
评分4.5 / 5.0
版本1.0.0
更新日期2026年3月25日
对比案例1 组

用户评分

4.5(5)
5
0%
4
0%
3
0%
2
0%
1
0%

为此 Skill 评分

0.0

兼容平台

🔧Claude Code

时间线

创建2026年3月26日
最后更新2026年3月25日