jpskill.com
📄 ドキュメント コミュニティ

template-engine

ユーザーが差し込み印刷、テンプレートへのデータ入力、書類作成などを依頼した場合に、DOCX、PDF、HTMLなど様々な形式で、スプレッドシート等のデータに基づき、文書テンプレートを自動で作成するSkill。

📜 元の英語説明(参考)

Auto-fill document templates with data. Use when a user asks to create a mail merge, fill templates with data, generate documents from a template, populate placeholders, bulk generate letters or invoices, or auto-fill forms from a spreadsheet. Supports any document format including DOCX, PDF, HTML, and plain text.

🇯🇵 日本人クリエイター向け解説

一言でいうと

ユーザーが差し込み印刷、テンプレートへのデータ入力、書類作成などを依頼した場合に、DOCX、PDF、HTMLなど様々な形式で、スプレッドシート等のデータに基づき、文書テンプレートを自動で作成するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o template-engine.zip https://jpskill.com/download/15464.zip && unzip -o template-engine.zip && rm template-engine.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15464.zip -OutFile "$d\template-engine.zip"; Expand-Archive "$d\template-engine.zip" -DestinationPath $d -Force; ri "$d\template-engine.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して template-engine.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → template-engine フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

テンプレートエンジン

概要

スプレッドシート、データベース、または JSON からのデータでドキュメントテンプレートを自動的に入力します。DOCX、PDF、HTML、Markdown、およびプレーンテキストなど、あらゆる形式の差し込み印刷をサポートします。単一のテンプレートとデータソースから、何百ものパーソナライズされたドキュメントを生成します。

手順

ユーザーがテンプレートベースのドキュメント生成を必要とする場合、形式とアプローチを決定します。

タスク A: python-docx-template を使用した DOCX テンプレートの入力

  1. ライブラリをインストールします。
pip install docxtpl openpyxl
  1. Jinja2 プレースホルダーを使用して DOCX テンプレートを作成します。

    • 単純な値には {{ variable }} を使用します
    • ループには {% for item in items %}...{% endfor %} を使用します
    • 条件分岐には {% if condition %}...{% endif %} を使用します
  2. テンプレートを入力します。

from docxtpl import DocxTemplate
import json

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

# 単一ドキュメント
data = {
    "client_name": "Acme Corp",
    "date": "2025-01-15",
    "items": [
        {"description": "Consulting", "amount": 5000},
        {"description": "Development", "amount": 12000},
    ],
    "total": 17000
}
fill_docx_template("invoice_template.docx", data, "invoice_acme.docx")
  1. CSV からの一括生成:
import csv
from docxtpl import DocxTemplate

def mail_merge_docx(template_path: str, csv_path: str, output_dir: str):
    with open(csv_path) as f:
        rows = list(csv.DictReader(f))

    for i, row in enumerate(rows):
        doc = DocxTemplate(template_path)
        doc.render(row)
        filename = f"{output_dir}/{row.get('name', i)}.docx"
        doc.save(filename)
        print(f"Generated: {filename}")

    print(f"Created {len(rows)} documents")

mail_merge_docx("letter_template.docx", "contacts.csv", "./output")

タスク B: Jinja2 を使用した HTML/Markdown テンプレート

from jinja2 import Environment, FileSystemLoader
import csv

env = Environment(loader=FileSystemLoader("./templates"))
template = env.get_template("report.html")

with open("data.csv") as f:
    rows = list(csv.DictReader(f))

for row in rows:
    html = template.render(**row)
    output_file = f"./output/{row['id']}_report.html"
    with open(output_file, "w") as out:
        out.write(html)

Jinja2 テンプレートの例 (templates/report.html):

<!DOCTYPE html>
<html>
<head><title>{{ company_name }} のレポート</title></head>
<body>
  <h1>月次レポート: {{ company_name }}</h1>
  <p>期間: {{ start_date }} から {{ end_date }}</p>
  <table>
    <tr><th>メトリック</th><th>値</th></tr>
    {% for metric in metrics %}
    <tr><td>{{ metric.name }}</td><td>{{ metric.value }}</td></tr>
    {% endfor %}
  </table>
</body>
</html>

タスク C: テンプレートからの PDF 生成

from jinja2 import Environment, FileSystemLoader
import pdfkit  # requires wkhtmltopdf installed

def generate_pdf_from_template(template_name: str, data: dict, output: str):
    env = Environment(loader=FileSystemLoader("./templates"))
    template = env.get_template(template_name)
    html = template.render(**data)
    pdfkit.from_string(html, output, options={"page-size": "A4", "encoding": "UTF-8"})

# Alternative: use weasyprint (pure Python, no external deps)
# pip install weasyprint
from weasyprint import HTML

def generate_pdf_weasyprint(template_name: str, data: dict, output: str):
    env = Environment(loader=FileSystemLoader("./templates"))
    template = env.get_template(template_name)
    html_content = template.render(**data)
    HTML(string=html_content).write_pdf(output)

タスク D: プレーンテキストテンプレート (メール、通知)

from string import Template
import csv

def text_mail_merge(template_str: str, csv_path: str) -> list[str]:
    template = Template(template_str)
    results = []
    with open(csv_path) as f:
        for row in csv.DictReader(f):
            results.append(template.safe_substitute(row))
    return results

# Usage
email_template = """Dear $name,

Thank you for your order #$order_id placed on $date.
Your total is $$amount.

Best regards,
The Team"""

messages = text_mail_merge(email_template, "orders.csv")
for msg in messages:
    print(msg)
    print("---")

例 1: パーソナライズされた採用通知書の生成

ユーザーリクエスト: 「テンプレートと従業員のスプレッドシートから 50 通の採用通知書を作成してください」

from docxtpl import DocxTemplate
import csv

with open("new_hires.csv") as f:
    hires = list(csv.DictReader(f))

for hire in hires:
    doc = DocxTemplate("offer_letter_template.docx")
    doc.render({
        "candidate_name": hire["name"],
        "position": hire["role"],
        "salary": f"${int(hire['salary']):,}",
        "start_date": hire["start_date"],
        "manager": hire["manager"]
    })
    doc.save(f"./offers/offer_{hire['name'].replace(' ', '_')}.docx")

print(f"Generated {len(hires)} offer letters in ./offers/")

例 2: JSON データからの請求書生成

ユーザーリクエスト: 「請求データ内のすべてのクライアントに対して PDF 請求書を生成してください」

from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
import json

with open("billing.json") as f:
    clients = json.load(f)

env = Environment(loader=FileSystemLoader("./templates"))
template = env.get_template("invoice.html")

for client in clients:
    client["total"] = sum(item["amount"] for item in client["line_items"])
    html = template.render(**client)
    HTML(string=html).write_pdf(f"./invoices/invoice_{client['id']}.pdf")

print(f"Generated {len(clients)} invoices")

例 3: スプレッドシートからのメールコンテンツの一括生成

ユーザーリクエスト: 「CSV から 200 件の連絡先に対してパーソナライズされたメール本文を作成してください」

from jinja2 import Environment, BaseLoader
import csv

template_str = """Hi {{ first_name }},

I noticed {{ company }} recently {{ trigger_event }}. We help companies
like yours with {{ pain_point }}.

Would you have 15 minutes this week t
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Template Engine

Overview

Auto-fill document templates with data from spreadsheets, databases, or JSON. Supports mail merge for any format: DOCX, PDF, HTML, Markdown, and plain text. Generate hundreds of personalized documents from a single template and data source.

Instructions

When a user needs template-based document generation, determine the format and approach:

Task A: DOCX template filling with python-docx-template

  1. Install the library:
pip install docxtpl openpyxl
  1. Create a DOCX template with Jinja2 placeholders:

    • Use {{ variable }} for simple values
    • Use {% for item in items %}...{% endfor %} for loops
    • Use {% if condition %}...{% endif %} for conditionals
  2. Fill the template:

from docxtpl import DocxTemplate
import json

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

# Single document
data = {
    "client_name": "Acme Corp",
    "date": "2025-01-15",
    "items": [
        {"description": "Consulting", "amount": 5000},
        {"description": "Development", "amount": 12000},
    ],
    "total": 17000
}
fill_docx_template("invoice_template.docx", data, "invoice_acme.docx")
  1. Bulk generation from CSV:
import csv
from docxtpl import DocxTemplate

def mail_merge_docx(template_path: str, csv_path: str, output_dir: str):
    with open(csv_path) as f:
        rows = list(csv.DictReader(f))

    for i, row in enumerate(rows):
        doc = DocxTemplate(template_path)
        doc.render(row)
        filename = f"{output_dir}/{row.get('name', i)}.docx"
        doc.save(filename)
        print(f"Generated: {filename}")

    print(f"Created {len(rows)} documents")

mail_merge_docx("letter_template.docx", "contacts.csv", "./output")

Task B: HTML/Markdown templates with Jinja2

from jinja2 import Environment, FileSystemLoader
import csv

env = Environment(loader=FileSystemLoader("./templates"))
template = env.get_template("report.html")

with open("data.csv") as f:
    rows = list(csv.DictReader(f))

for row in rows:
    html = template.render(**row)
    output_file = f"./output/{row['id']}_report.html"
    with open(output_file, "w") as out:
        out.write(html)

Example Jinja2 template (templates/report.html):

<!DOCTYPE html>
<html>
<head><title>Report for {{ company_name }}</title></head>
<body>
  <h1>Monthly Report: {{ company_name }}</h1>
  <p>Period: {{ start_date }} to {{ end_date }}</p>
  <table>
    <tr><th>Metric</th><th>Value</th></tr>
    {% for metric in metrics %}
    <tr><td>{{ metric.name }}</td><td>{{ metric.value }}</td></tr>
    {% endfor %}
  </table>
</body>
</html>

Task C: PDF generation from templates

from jinja2 import Environment, FileSystemLoader
import pdfkit  # requires wkhtmltopdf installed

def generate_pdf_from_template(template_name: str, data: dict, output: str):
    env = Environment(loader=FileSystemLoader("./templates"))
    template = env.get_template(template_name)
    html = template.render(**data)
    pdfkit.from_string(html, output, options={"page-size": "A4", "encoding": "UTF-8"})

# Alternative: use weasyprint (pure Python, no external deps)
# pip install weasyprint
from weasyprint import HTML

def generate_pdf_weasyprint(template_name: str, data: dict, output: str):
    env = Environment(loader=FileSystemLoader("./templates"))
    template = env.get_template(template_name)
    html_content = template.render(**data)
    HTML(string=html_content).write_pdf(output)

Task D: Plain text templates (emails, notifications)

from string import Template
import csv

def text_mail_merge(template_str: str, csv_path: str) -> list[str]:
    template = Template(template_str)
    results = []
    with open(csv_path) as f:
        for row in csv.DictReader(f):
            results.append(template.safe_substitute(row))
    return results

# Usage
email_template = """Dear $name,

Thank you for your order #$order_id placed on $date.
Your total is $$amount.

Best regards,
The Team"""

messages = text_mail_merge(email_template, "orders.csv")
for msg in messages:
    print(msg)
    print("---")

Examples

Example 1: Generate personalized offer letters

User request: "Create 50 offer letters from a template and employee spreadsheet"

from docxtpl import DocxTemplate
import csv

with open("new_hires.csv") as f:
    hires = list(csv.DictReader(f))

for hire in hires:
    doc = DocxTemplate("offer_letter_template.docx")
    doc.render({
        "candidate_name": hire["name"],
        "position": hire["role"],
        "salary": f"${int(hire['salary']):,}",
        "start_date": hire["start_date"],
        "manager": hire["manager"]
    })
    doc.save(f"./offers/offer_{hire['name'].replace(' ', '_')}.docx")

print(f"Generated {len(hires)} offer letters in ./offers/")

Example 2: Invoice generation from JSON data

User request: "Generate PDF invoices for all clients in our billing data"

from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
import json

with open("billing.json") as f:
    clients = json.load(f)

env = Environment(loader=FileSystemLoader("./templates"))
template = env.get_template("invoice.html")

for client in clients:
    client["total"] = sum(item["amount"] for item in client["line_items"])
    html = template.render(**client)
    HTML(string=html).write_pdf(f"./invoices/invoice_{client['id']}.pdf")

print(f"Generated {len(clients)} invoices")

Example 3: Bulk email content from a spreadsheet

User request: "Create personalized email bodies for 200 contacts from a CSV"

from jinja2 import Environment, BaseLoader
import csv

template_str = """Hi {{ first_name }},

I noticed {{ company }} recently {{ trigger_event }}. We help companies
like yours with {{ pain_point }}.

Would you have 15 minutes this week to discuss?

Best,
{{ sender_name }}"""

env = Environment(loader=BaseLoader())
template = env.from_string(template_str)

with open("contacts.csv") as f:
    contacts = list(csv.DictReader(f))

for contact in contacts:
    email_body = template.render(**contact)
    with open(f"./emails/{contact['email']}.txt", "w") as out:
        out.write(email_body)

print(f"Generated {len(contacts)} email drafts")

Guidelines

  • Always validate data before rendering templates. Check for missing required fields.
  • Use safe_substitute or Jinja2's default filter to handle missing values gracefully: {{ name | default("Valued Customer") }}.
  • Preview the first 2-3 generated documents before running a full batch.
  • Keep templates in version control separate from data files.
  • For DOCX templates, test with complex formatting (tables, images, headers) early since not all features are supported.
  • Sanitize user-provided data to prevent template injection in HTML output.
  • Use consistent naming for output files that includes a unique identifier.
  • For large batches (1000+ documents), process in chunks and report progress.