reliable-excel-workbook-creation
Skill này làm gì
Skill này chỉ cho AI agent cách tạo các file Excel phức tạp bằng Python trong một script gọn gàng. Nó dành cho những người cần workbook nhiều sheet với dữ liệu và định dạng.
Khi nào nên dùng
- ✓Khi bạn cần một workbook Excel có nhiều sheet, dữ liệu và định dạng.
- ✓Khi trình đọc file không mở được một file XLSX hiện có một cách đúng đắn.
- ✓Khi một công việc workbook nhiều bước thất bại trong sandbox.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-excel-workbook-creation/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tạo workbook Excel ba sheet cho ngân sách của tôi, với tiêu đề in đậm. Dùng một script lưu nó vào thư mục làm việc của tôi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent chuyển sang thư mục làm việc và chạy một script Python trong shell để tạo workbook, thêm dữ liệu, định dạng và lưu nó bằng đường dẫn file đầy đủ.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Reliable Excel Workbook Creation via Shell
When to Use This Pattern
Use this technique when you need to:
- Create complex Excel workbooks with multiple sheets
- Perform multi-step workbook operations (create, populate, format, save)
- Work with XLSX files that
read_filecannot handle properly - Avoid failures from
execute_code_sandboxon persistent file operations
Avoid: read_file for XLSX files, execute_code_sandbox for multi-step workbook creation
Core Pattern
cd /workspace && python3 << 'EOF'
from openpyxl import Workbook
# Your Excel operations here
wb = Workbook()
# ... create sheets, add data, save
wb.save('/workspace/filename.xlsx')
EOF
Step-by-Step Instructions
Step 1: Change to Workspace Directory
Always start with cd /workspace && to ensure file paths resolve correctly.
Step 2: Use Heredoc with Single-Quoted EOF
Use << 'EOF' (single quotes) to prevent shell variable expansion within the Python code.
Step 3: Write Complete Python Script
Include all imports, workbook creation, data population, and save operations in one script.
Step 4: Use Absolute Paths for Save Operations
Always save with full path: /workspace/your_filename.xlsx
Complete Example
cd /workspace && python3 << 'EOF'
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill
# Create workbook
wb = Workbook()
# Create multiple sheets
sheets = ['Summary', 'Data', 'Analysis', 'Settings']
for sheet_name in sheets:
wb.create_sheet(title=sheet_name)
# Remove default sheet if needed
if 'Sheet' in wb.sheetnames:
del wb['Sheet']
# Populate data
ws = wb['Data']
ws['A1'] = 'Item'
ws['B1'] = 'Value'
ws['A2'] = 'Revenue'
ws['B2'] = 100000
# Apply formatting
header_font = Font(bold=True)
for cell in ws['1:1']:
cell.font = header_font
# Save workbook
wb.save('/workspace/report.xlsx')
print('Workbook created successfully: /workspace/report.xlsx')
EOF
Why This Works
| Approach | Problem | Solution |
|---|---|---|
read_file |
Cannot parse XLSX binary format | Don't use for Excel files |
execute_code_sandbox |
File persistence issues, multi-step failures | Use run_shell instead |
run_shell with heredoc |
✓ Reliable, full control, persistent files | Use this pattern |
Common Operations
Create Multi-Sheet Workbook
cd /workspace && python3 << 'EOF'
from openpyxl import Workbook
wb = Workbook()
sheet_names = ['Sheet1', 'Sheet2', 'Sheet3']
for name in sheet_names:
wb.create_sheet(title=name)
wb.save('/workspace/multi_sheet.xlsx')
EOF
Read and Modify Existing Workbook
cd /workspace && python3 << 'EOF'
from openpyxl import load_workbook
wb = load_workbook('/workspace/existing.xlsx')
ws = wb.active
ws['A1'] = 'Updated Value'
wb.save('/workspace/existing.xlsx')
EOF
Add Formulas
cd /workspace && python3 << 'EOF'
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws['A1'] = 100
ws['A2'] = 200
ws['A3'] = '=SUM(A1:A2)'
wb.save('/workspace/with_formulas.xlsx')
EOF
Troubleshooting
- File not found: Ensure you use
/workspace/prefix in all paths - Permission errors: Verify workspace directory is writable
- Module not found: openpyxl is pre-installed in the environment
- Heredoc issues: Use single-quoted
'EOF'to prevent shell interpretation
Best Practices
- Always use absolute paths (
/workspace/filename.xlsx) - Single-quoted heredoc (
<< 'EOF') prevents variable expansion - Complete script in one heredoc - avoid splitting operations
- Print confirmation after save to verify success
- Handle exceptions for production scripts
Câu hỏi thường gặp
Tại sao dùng đường dẫn lưu đầy đủ?
Đường dẫn đầy đủ đảm bảo file được lưu đúng nơi bạn mong đợi, chứ không phải trong thư mục khác.
Script có định dạng được các ô không?
Có, ví dụ trong skill đặt phông chữ, màu nền và căn lề trong workbook.
Tại sao tránh trình đọc file cho XLSX ở đây?
Skill lưu ý rằng trình đọc đôi khi không xử lý đúng file XLSX, nên nó ghi file trực tiếp.
Chi tiết
Mô tả gốc của tác giả
Use run_shell with cd and heredoc syntax for complex Excel operations when read_file fails on XLSX or execute_code_sandbox fails on multi-step workbook creation
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12966
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
feishu-doc
394kGiúp agent của bạn đọc, tạo và sửa tài liệu đám mây Feishu, gồm văn bản, hình ảnh và bảng, bằng công cụ tài liệu.
feishu-drive
394kCho phép agent của bạn duyệt, sắp xếp và bình luận các file trong một thư mục đám mây Feishu đã được chia sẻ với bot.
feishu-perm
394kGiúp agent của bạn kiểm tra và thay đổi ai có quyền truy cập một file Feishu, chọn quyền nhỏ nhất đáp ứng yêu cầu của bạn.