excel-heredoc-workaround
Skill này làm gì
Skill này là cách khắc phục để tạo sổ tính Excel bằng openpyxl khi sandbox code gặp sự cố. Dành cho người cần bảng tính có tiêu đề có cấu trúc và kiểu dáng.
Khi nào nên dùng
- ✓Khi tạo tệp .xlsx thất bại trong sandbox vì sự cố openpyxl.
- ✓Khi tôi cần bảng tính có tiêu đề định dạng, viền và bố cục lịch.
- ✓Khi tôi có thể chạy Python trực tiếp từ shell trên máy tính này.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/excel-heredoc-workaround/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
“Hãy tạo một lịch Excel có tiêu đề định dạng và viền. Sandbox đang lỗi, nên hãy chạy từ shell.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI thử sandbox trước, và nếu thất bại thì chạy một script openpyxl trực tiếp từ shell, tạo sổ tính, định dạng tiêu đề và lưu tệp.
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.
Excel Heredoc Workaround
Purpose
When creating Excel files with openpyxl, execute_code_sandbox may fail due to environment issues. This skill provides a robust workaround: fall back to run_shell with inline Python heredoc scripts to create properly formatted spreadsheets with styling.
When to Use
- You need to create
.xlsxfiles with openpyxl execute_code_sandboxfails with openpyxl-related errors- You need styling, formatting, or complex spreadsheet features
- Direct shell execution with Python heredoc is available
Step-by-Step Instructions
Step 1: Attempt execute_code_sandbox First
Try creating the Excel file using execute_code_sandbox:
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill
wb = Workbook()
ws = wb.active
ws.title = "Data"
# Add data and styling
ws['A1'] = "Header"
ws['A1'].font = Font(bold=True)
wb.save("output.xlsx")
print("ARTIFACT_PATH:output.xlsx")
Step 2: If Sandbox Fails, Use run_shell with Heredoc
When execute_code_sandbox fails, switch to run_shell with a Python heredoc:
python3 << 'EOF'
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side
# Create workbook
wb = Workbook()
ws = wb.active
ws.title = "Schedule"
# Add headers with styling
headers = ["Task", "Date", "Status", "Priority"]
for col, header in enumerate(headers, 1):
cell = ws.cell(row=1, column=col, value=header)
cell.font = Font(bold=True, size=12)
cell.fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")
cell.font = Font(bold=True, color="FFFFFF")
cell.alignment = Alignment(horizontal="center")
# Add data rows
data = [
["Cleanup Zone A", "2024-01-15", "Pending", "High"],
["Cleanup Zone B", "2024-01-16", "Complete", "Medium"],
]
for row_idx, row_data in enumerate(data, 2):
for col_idx, value in enumerate(row_data, 1):
cell = ws.cell(row=row_idx, column=col_idx, value=value)
cell.alignment = Alignment(horizontal="left")
# Adjust column widths
for col in ws.columns:
max_length = 0
column = col[0].column_letter
for cell in col:
try:
if len(str(cell.value)) > max_length:
max_length = len(str(cell.value))
except:
pass
ws.column_dimensions[column].width = max_length + 2
# Save the file
wb.save("Cleanup_Schedule.xlsx")
print("Created Cleanup_Schedule.xlsx successfully")
EOF
Step 3: Verify File Creation
After running the heredoc script, verify the file was created:
ls -lh *.xlsx
Step 4: Optional - Read Back to Confirm
Use read_file to confirm the Excel file is valid:
read_file with filetype="xlsx", file_path="Cleanup_Schedule.xlsx"
Key Advantages
| Aspect | execute_code_sandbox | run_shell heredoc |
|---|---|---|
| Reliability | May fail with openpyxl | More stable execution |
| Styling support | Limited | Full openpyxl support |
| File output | Via ARTIFACT_PATH | Direct file write |
| Debugging | Limited output | Full stdout/stderr |
Common Styling Patterns
Bold Headers with Colored Background
from openpyxl.styles import Font, PatternFill
header_fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")
header_font = Font(bold=True, color="FFFFFF", size=12)
cell = ws.cell(row=1, column=1, value="Header")
cell.fill = header_fill
cell.font = header_font
Alternating Row Colors
from openpyxl.styles import PatternFill
gray_fill = PatternFill(start_color="D9D9D9", end_color="D9D9D9", fill_type="solid")
for row in range(2, ws.max_row + 1):
if row % 2 == 0:
for col in range(1, ws.max_column + 1):
ws.cell(row=row, column=col).fill = gray_fill
Borders and Alignment
from openpyxl.styles import Border, Side, Alignment
thin_border = Border(
left=Side(style='thin'),
right=Side(style='thin'),
top=Side(style='thin'),
bottom=Side(style='thin')
)
for row in ws.iter_rows():
for cell in row:
cell.border = thin_border
cell.alignment = Alignment(horizontal="center", vertical="center")
Troubleshooting
Issue: File not created after heredoc execution
- Fix: Check stdout for Python errors; ensure working directory is correct
Issue: openpyxl not found
- Fix: Install with
pip install openpyxlbefore running her
Câu hỏi thường gặp
Có thử sandbox trước không?
Có. Hướng dẫn nói nên thử sandbox trước và chỉ chuyển khi nó thất bại.
Ví dụ có kiểu dáng gì?
Các ví dụ gồm chữ đậm, màu nền, căn lề và viền.
Làm sao tìm được tệp đã lưu?
Ví dụ in một dấu đường dẫn sau khi lưu, nên có thể tìm được tệp đầu ra.
Chi tiết
Mô tả gốc của tác giả
Create Excel files with openpyxl by falling back to run_shell with inline Python heredoc when execute_code_sandbox fails
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12875
- 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.