Claude Skills — Tạo Excel, PowerPoint, PDF tự động
Điểm nổi bật
Nhấn để đến mục tương ứng
- 1 Áp dụng ngay: Skills là các tool đặc biệt cho phép Claude thực hiện actions cụ thể vượt ra ngoài việc tạo text — phần này cung cấp quy trình cụ thể giúp bạn triển khai hiệu quả mà không cần thử nghiệm nhiều lần.
- 2 Góc nhìn thực tế: pip install openpyxl python-pptx reportlab anthropic. Điều quan trọng là hiểu rõ khi nào nên và không nên áp dụng phương pháp này.
- 3 Lợi ích đo lường được: Pattern hiệu quả nhất: Claude tạo code để generate Excel, sau đó bạn execute code đó: import anthropic import. Phương pháp này giúp tiết kiệm đáng kể thời gian so với cách làm truyền thống.
- 4 Bước đầu tiên bạn nên làm: Khi bạn có data cụ thể và muốn kiểm soát nhiều hơn: import openpyxl from openpyxl.styles import Font, PatternFill,. Áp dụng đúng cách sẽ thấy kết quả rõ rệt từ tuần đầu tiên.
- 5 Một điều ít người đề cập: from pptx import Presentation from pptx.util import Inches, Pt, Emu from pptx.dml.color import RGBColor from. Hiểu rõ bối cảnh áp dụng sẽ quyết định 80% thành công khi triển khai.
Một trong những use case phổ biến nhất trong doanh nghiệp: tạo tài liệu lặp đi lặp lại. Báo cáo hàng tuần, slide cập nhật cho management, invoice tháng — những tác vụ này tốn hàng giờ mỗi tuần. Claude Skills cho document generation giúp bạn tự động hóa hoàn toàn quy trình này.
Claude Skills là gì?
Skills là các tool đặc biệt cho phép Claude thực hiện actions cụ thể vượt ra ngoài việc tạo text. Với document generation skills, Claude có thể:
- Tạo file Excel (.xlsx) với formulas, charts, và conditional formatting
- Tạo file PowerPoint (.pptx) với layouts, images, và animations
- Tạo file PDF với typography và layout chuyên nghiệp
- Điền vào templates có sẵn với dữ liệu động
Setup: Cài đặt thư viện cần thiết
pip install openpyxl python-pptx reportlab anthropic
Tạo Excel với Python + Claude
Pattern hiệu quả nhất: Claude tạo code để generate Excel, sau đó bạn execute code đó:
import anthropic
import subprocess
import tempfile
import os
client = anthropic.Anthropic()
def generate_excel_report(data_description: str, output_path: str):
"""Claude tạo code Python để build Excel file"""
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=4000,
system="""You are an expert Python developer specializing in Excel automation with openpyxl.
Write complete, runnable Python code that creates professional Excel files.
Always include: proper formatting, headers, borders, column widths, and data validation where appropriate.""",
messages=[{
"role": "user",
"content": f"""Write Python code using openpyxl to create an Excel file.
Requirements:
{data_description}
Output path: {output_path}
The code must:
1. Create the workbook and sheets
2. Add headers with styling (bold, background color)
3. Add sample/placeholder data rows
4. Set appropriate column widths
5. Add borders and alternating row colors
6. Save to the output path
Write ONLY the Python code, no explanations."""
}]
)
code = response.content[0].text
# Extract Python code nếu có markdown
if "'''python" in code:
code = code.split("'''python")[1].split("'''")[0]
elif "'''" in code:
code = code.split("'''")[1].split("'''")[0]
# Execute code trong temp file
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
f.write(code)
temp_path = f.name
try:
result = subprocess.run(['python', temp_path], capture_output=True, text=True)
if result.returncode != 0:
return {"success": False, "error": result.stderr, "code": code}
return {"success": True, "path": output_path, "code": code}
finally:
os.unlink(temp_path)
# Sử dụng
result = generate_excel_report(
data_description="""
Quarterly Sales Report with:
- Sheet 1: Summary with KPIs (Revenue, Units Sold, Avg Order Value, Growth %)
- Sheet 2: Monthly breakdown table (Jan-Dec) for each product category
- Sheet 3: Top 10 customers table with: name, total spend, orders, last order date
- All monetary values formatted as currency (USD)
- Conditional formatting: green for positive growth, red for negative
""",
output_path="/tmp/quarterly_report.xlsx"
)
print(f"Excel created: {result['path']}" if result['success'] else f"Error: {result['error']}")
Tạo Excel trực tiếp với openpyxl
Khi bạn có data cụ thể và muốn kiểm soát nhiều hơn:
import openpyxl
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter
from openpyxl.chart import BarChart, Reference
def create_sales_dashboard(data: dict, output_path: str):
"""Tạo Excel dashboard với data thực tế"""
wb = openpyxl.Workbook()
# === Sheet 1: Summary ===
ws_summary = wb.active
ws_summary.title = "Summary"
# Header styling
header_font = Font(bold=True, color="FFFFFF", size=12)
header_fill = PatternFill(start_color="2E4057", end_color="2E4057", fill_type="solid")
header_alignment = Alignment(horizontal="center", vertical="center")
headers = ["Metric", "Q1", "Q2", "Q3", "Q4", "Total"]
for col, header in enumerate(headers, 1):
cell = ws_summary.cell(row=1, column=col, value=header)
cell.font = header_font
cell.fill = header_fill
cell.alignment = header_alignment
# Data rows
metrics = data.get("metrics", [
{"name": "Revenue ($)", "values": [125000, 142000, 158000, 189000]},
{"name": "Units Sold", "values": [1250, 1420, 1580, 1890]},
{"name": "New Customers", "values": [45, 52, 61, 78]},
])
alt_fill = PatternFill(start_color="F0F4F8", end_color="F0F4F8", fill_type="solid")
for row_idx, metric in enumerate(metrics, 2):
ws_summary.cell(row=row_idx, column=1, value=metric["name"])
total = 0
for col_idx, val in enumerate(metric["values"], 2):
cell = ws_summary.cell(row=row_idx, column=col_idx, value=val)
total += val
if row_idx % 2 == 0:
cell.fill = alt_fill
total_cell = ws_summary.cell(row=row_idx, column=6, value=total)
total_cell.font = Font(bold=True)
# Auto-fit columns
for col in ws_summary.columns:
max_width = max(len(str(cell.value or "")) for cell in col) + 4
ws_summary.column_dimensions[get_column_letter(col[0].column)].width = max_width
# === Sheet 2: Chart ===
ws_chart = wb.create_sheet("Charts")
# Add data for chart
chart_data = [["Quarter", "Revenue"]]
quarters = ["Q1", "Q2", "Q3", "Q4"]
revenues = [125000, 142000, 158000, 189000]
for q, r in zip(quarters, revenues):
chart_data.append([q, r])
for row in chart_data:
ws_chart.append(row)
# Create bar chart
chart = BarChart()
chart.type = "col"
chart.title = "Quarterly Revenue"
chart.y_axis.title = "Revenue ($)"
chart.x_axis.title = "Quarter"
data_ref = Reference(ws_chart, min_col=2, min_row=1, max_row=5)
cats = Reference(ws_chart, min_col=1, min_row=2, max_row=5)
chart.add_data(data_ref, titles_from_data=True)
chart.set_categories(cats)
chart.shape = 4
ws_chart.add_chart(chart, "D2")
wb.save(output_path)
return output_path
# Tạo file
create_sales_dashboard({}, "/tmp/sales_dashboard.xlsx")
Tạo PowerPoint với python-pptx
from pptx import Presentation
from pptx.util import Inches, Pt, Emu
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
def create_presentation(content: dict, output_path: str):
"""Tạo PowerPoint từ structured content"""
prs = Presentation()
# Slide dimensions (widescreen 16:9)
prs.slide_width = Inches(13.33)
prs.slide_height = Inches(7.5)
# Colors
PRIMARY = RGBColor(0x2E, 0x40, 0x57)
ACCENT = RGBColor(0x06, 0x8D, 0x9D)
WHITE = RGBColor(0xFF, 0xFF, 0xFF)
def add_title_slide(title: str, subtitle: str):
layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(layout)
title_shape = slide.shapes.title
title_shape.text = title
title_shape.text_frame.paragraphs[0].font.color.rgb = WHITE
title_shape.text_frame.paragraphs[0].font.size = Pt(44)
title_shape.text_frame.paragraphs[0].font.bold = True
subtitle_shape = slide.placeholders[1]
subtitle_shape.text = subtitle
def add_content_slide(title: str, bullets: list[str]):
layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(layout)
slide.shapes.title.text = title
tf = slide.placeholders[1].text_frame
tf.clear()
for i, bullet in enumerate(bullets):
if i == 0:
p = tf.paragraphs[0]
else:
p = tf.add_paragraph()
p.text = bullet
p.level = 0
p.font.size = Pt(20)
def add_stats_slide(title: str, stats: list[dict]):
"""Slide với big number statistics"""
layout = prs.slide_layouts[6] # Blank
slide = prs.slides.add_slide(layout)
# Title
txBox = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(12), Inches(1))
tf = txBox.text_frame
tf.text = title
tf.paragraphs[0].font.size = Pt(32)
tf.paragraphs[0].font.bold = True
# Stats boxes
box_width = Inches(2.8)
for i, stat in enumerate(stats[:4]):
left = Inches(0.5 + i * 3.1)
top = Inches(2.0)
# Number
num_box = slide.shapes.add_textbox(left, top, box_width, Inches(1.5))
tf = num_box.text_frame
tf.text = stat["value"]
tf.paragraphs[0].font.size = Pt(48)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = ACCENT
tf.paragraphs[0].alignment = PP_ALIGN.CENTER
# Label
label_box = slide.shapes.add_textbox(left, Inches(3.6), box_width, Inches(0.8))
tf = label_box.text_frame
tf.text = stat["label"]
tf.paragraphs[0].alignment = PP_ALIGN.CENTER
# Build presentation
add_title_slide(
content.get("title", "Company Report"),
content.get("subtitle", "Q4 2024")
)
for slide_data in content.get("slides", []):
if slide_data["type"] == "bullets":
add_content_slide(slide_data["title"], slide_data["bullets"])
elif slide_data["type"] == "stats":
add_stats_slide(slide_data["title"], slide_data["stats"])
prs.save(output_path)
return output_path
# Ví dụ sử dụng
content = {
"title": "Annual Business Review 2024",
"subtitle": "Growth & Strategy Update",
"slides": [
{
"type": "stats",
"title": "Key Performance Indicators",
"stats": [
{"value": "$2.4M", "label": "Total Revenue"},
{"value": "89%", "label": "Customer Retention"},
{"value": "342", "label": "New Clients"},
{"value": "+34%", "label": "YoY Growth"}
]
},
{
"type": "bullets",
"title": "2025 Strategic Priorities",
"bullets": [
"Expand into Southeast Asian markets",
"Launch AI-powered product features",
"Grow enterprise customer segment",
"Achieve profitability by Q3"
]
}
]
}
create_presentation(content, "/tmp/annual_review.pptx")
Kết hợp Claude để tạo nội dung + tài liệu
Pattern mạnh nhất: Claude tạo cả nội dung lẫn structure:
def ai_powered_report(topic: str, data_points: list[str], output_path: str):
"""Claude tạo nội dung, Python tạo file"""
# Bước 1: Claude lên kế hoạch nội dung
content_response = client.messages.create(
model="claude-opus-4-5",
max_tokens=3000,
messages=[{
"role": "user",
"content": f"""Create a structured report outline for: {topic}
Data available:
{chr(10).join(data_points)}
Return JSON with structure:
{{
"title": "...",
"subtitle": "...",
"executive_summary": "2-3 sentences",
"slides": [
{{
"type": "bullets|stats",
"title": "...",
"bullets": ["..."] or "stats": [{{"value": "...", "label": "..."}}]
}}
]
}}"""
}]
)
try:
text = content_response.content[0].text
start = text.find('{')
end = text.rfind('}') + 1
content = json.loads(text[start:end])
except Exception:
content = {"title": topic, "slides": []}
# B��ớc 2: Tạo PowerPoint
create_presentation(content, output_path)
return output_path
Tổng kết
Document automation với Claude và Python libraries mang lại lợi thế lớn:
- openpyxl cho Excel với full control over formatting, formulas, charts
- python-pptx cho PowerPoint với custom layouts và styling
- Claude làm "brain" — quyết định nội dung, structure, và format phù hợp
Khám phá tiếp: Claude Skills cho Tài chính — dashboard và phân tích portfolio tự động.
Bài viết liên quan
Bai viet co huu ich khong?
Bản quyền thuộc về tác giả. Vui lòng dẫn nguồn khi chia sẻ.






