본문으로 건너뛰기
Skillpedia
PDF, Word, 슬라이드7.8k · #12966

reliable-excel-workbook-creation

하는 일

이 스킬은 하나의 깔끔한 Python 스크립트로 복잡한 Excel 파일을 만드는 방법을 AI 에이전트에게 보여 줍니다. 데이터와 서식이 있는 여러 시트짜리 통합 문서가 필요한 사람에게 맞습니다.

사용하는 경우

  • ✓데이터와 서식이 있는 여러 시트짜리 Excel 통합 문서가 필요할 때.
  • ✓파일 읽기 도구가 기존 XLSX 파일을 제대로 열지 못하는 경우.
  • ✓샌드박스에서 여러 단계로 된 통합 문서 작업이 실패할 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-excel-workbook-creation/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-excel-workbook-creation/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 예산을 위해 시트 세 개짜리 Excel 통합 문서를 만들어 주세요. 제목은 굵게 해 주세요. 작업 공간에 저장하는 스크립트를 써 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 작업 공간 폴더로 이동한 뒤, 셸에서 Python 스크립트 하나를 실행합니다. 이 스크립트는 통합 문서를 만들고, 데이터를 넣고, 서식을 적용하고, 전체 경로로 저장합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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_file cannot handle properly
  • Avoid failures from execute_code_sandbox on 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

  1. Always use absolute paths (/workspace/filename.xlsx)
  2. Single-quoted heredoc (<< 'EOF') prevents variable expansion
  3. Complete script in one heredoc - avoid splitting operations
  4. Print confirmation after save to verify success
  5. Handle exceptions for production scripts
자주 묻는 질문

저장 경로를 전체로 쓰는 이유는 무엇인가요?

전체 경로를 쓰면 파일이 다른 폴더가 아니라 예상한 위치에 저장되도록 보장할 수 있습니다.

스크립트가 셀 서식을 지정할 수 있나요?

네, 스킬의 예제는 통합 문서의 글꼴, 채우기, 정렬을 설정합니다.

XLSX에는 왜 파일 읽기 도구를 쓰지 않나요?

스킬은 그 도구가 XLSX 파일을 제대로 다루지 못할 때가 있어서 파일을 직접 쓴다고 설명합니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
7.8k
순위
#12966
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬