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

spreadsheet-python-file-exec

하는 일

이 스킬은 AI 에이전트가 인라인 셸 명령 대신 저장된 Python 파일로 Excel 작업을 실행하는 방법을 보여 줍니다. 코드를 인라인으로 넘길 때 알 수 없는 오류가 나는 스프레드시트 작업을 하는 사람을 위한 스킬입니다.

사용하는 경우

  • ✓셸 에이전트를 통해 인라인으로 실행할 때 스프레드시트 스크립트에서 알 수 없는 오류가 날 때.
  • ✓Excel 작업에 여러 시트, 수식 또는 서식 단계가 있어 세밀한 제어가 필요할 때.
  • ✓스크립트를 파일로 저장해 다시 실행하고 쉽게 고치고 싶을 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/spreadsheet-direct-python-enhanced/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/spreadsheet-direct-python-enhanced/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 스크립트가 인라인으로 실행하면 계속 실패합니다. Python 파일로 저장해서 바로 실행하고 결과를 보여 주세요.”

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

작동 방식

에이전트는 먼저 Python 코드를 .py 파일로 씁니다. 그다음 python3로 그 파일을 셸에서 실행합니다. 이렇게 하면 셸 에이전트를 멈추게 할 수 있는 heredoc 구문 분석 문제를 피할 수 있습니다.

기술 내용 (원본 SKILL.md)

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

Direct Python Execution for Spreadsheet Tasks

When to Use This Skill

Use direct run_shell with Python scripts for spreadsheet operations when:

  • Reading or writing complex Excel files with multiple sheets
  • Applying formulas, formatting, or data transformations
  • Working with openpyxl, pandas, or similar libraries
  • The operation involves multiple steps that could exceed agent step limits
  • You need precise control over error handling and debugging
  • Complex scripts benefit from file-based execution for better reliability

Why Direct Execution?

The shell_agent tool can:

  • Hit maximum step limits on complex multi-step operations
  • Produce unexplained errors on formatting operations
  • Fail on intricate spreadsheet reads/writes due to iterative parsing
  • Fail to parse heredoc syntax correctly, causing 'unknown error' failures

Direct run_shell with Python is more reliable because it:

  • Executes in a single step with no iteration limits
  • Provides clearer, immediate error messages
  • Handles complex operations without step constraints
  • Gives full control over library imports and execution flow
  • Writing scripts to .py files first avoids shell_agent parsing issues with heredocs

How to Use

Recommended Pattern: Write Script to File First

For complex multi-line scripts, especially when using shell_agent as executor:

# Step 1: Write the Python script to a file
cat > process_spreadsheet.py << 'EOF'
import openpyxl
from openpyxl import Workbook

# Your spreadsheet code here
wb = openpyxl.load_workbook('file.xlsx')
# ... operations ...
wb.save('output.xlsx')
print('Success')
EOF

# Step 2: Execute the script
python3 process_spreadsheet.py

Alternative Pattern: Inline Heredoc (Simple Scripts Only)

For short, simple scripts when NOT using shell_agent as the executor:

python3 << 'EOF'
import openpyxl
from openpyxl import Workbook

# Your spreadsheet code here
wb = openpyxl.load_workbook('file.xlsx')
# ... operations ...
wb.save('output.xlsx')
print('Success')
EOF

Example 1: Read and Transform Excel Data

Write to file first, then execute:

import pandas as pd

# Load data from specific sheet
df = pd.read_excel('input.xlsx', sheet_name='Revenue')

# Apply transformations
df['Net_Revenue'] = df['Gross_Revenue'] * (1 - df['Tax_Rate'])

# Save results
df.to_excel('output.xlsx', index=False, sheet_name='Processed')

Example 2: Multi-Sheet Operations with openpyxl

Write to file first, then execute:

from openpyxl import load_workbook

wb = load_workbook('tour_data.xlsx')

# Iterate through sheets
for sheet_name in wb.sheetnames:
    ws = wb[sheet_name]
    # Apply formatting or calculations
    for row in ws.iter_rows(min_row=2, max_col=5):
        # Process cells
        pass

wb.save('tour_data_processed.xlsx')

Example 3: Complex Formatting Operations

Write to file first, then execute:

from openpyxl import load_workbook
from openpyxl.styles import Font, PatternFill, Alignment

wb = load_workbook('report.xlsx')
ws = wb.active

# Apply header styling
header_fill = PatternFill(start_color='4472C4', fill_type='solid')
header_font = Font(bold=True, color='FFFFFF')

for cell in ws[1]:
    cell.fill = header_fill
    cell.font = header_font
    cell.alignment = Alignment(horizontal='center')

wb.save('report_formatted.xlsx')

Example 4: Error Handling Pattern

Write to file first, then execute:

import sys
from openpyxl import load_workbook

try:
    wb = load_workbook('data.xlsx')
    ws = wb.active
    
    # Your operations here
    value = ws['A1'].value
    
    wb.save('output.xlsx')
    print(f"Success: Processed {ws.max_row} rows")
    
except Exception as e:
    print(f"Error: {str(e)}", file=sys.stderr)
    sys.exit(1)

Best Practices

  1. Prefer file-based execution for complex scripts: write to .py file first, then execute via run_shell
  2. Import only needed libraries to reduce execution time
  3. Print clear success/error messages for debugging
  4. Save intermediate results for complex multi-step transformations
  5. Test with small data before scaling to large spreadsheets
  6. Use pandas for data manipulation and openpyxl for formatting when both are needed
  7. Clean up temporary script files after execution if they won't be reused

When NOT to Use This Skill

  • Simple single-cell reads/writes (use shell_agent or basic commands)
  • Operations
자주 묻는 질문

왜 스크립트를 먼저 파일로 쓰나요?

스킬은 저장된 파일이 알 수 없는 오류를 일으키는 heredoc 구문 분석 문제를 피하게 한다고 설명합니다.

이 스킬에 특별한 라이브러리가 필요한가요?

아니요, openpyxl과 pandas처럼 스프레드시트에 흔히 쓰이는 Python 라이브러리와 함께 작동합니다.

수정 후 스크립트를 다시 실행할 수 있나요?

네, 저장된 파일은 다시 입력하지 않고 고쳐서 다시 실행할 수 있습니다.

상세 정보

작성자의 원본 설명

Execute Python scripts from files for reliable spreadsheet operations, avoiding heredoc issues with shell_agent

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬