Zum Inhalt springen
Skillpedia
PDF, Word & Folien7.8k · #12966

reliable-excel-workbook-creation

Was er macht

Dieser Skill zeigt dem KI-Agenten, wie komplexe Excel-Dateien mit Python in einem sauberen Skript entstehen. Er richtet sich an Menschen, die Arbeitsmappen mit mehreren Blättern, Daten und Formatierung brauchen.

Wann du ihn nutzt

  • ✓Wenn du eine Excel-Arbeitsmappe mit mehreren Blättern, Daten und Formatierung brauchst.
  • ✓Wenn das Werkzeug zum Lesen von Dateien eine vorhandene XLSX-Datei nicht richtig öffnen kann.
  • ✓Wenn ein mehrstufiger Tabellenauftrag in der Sandbox scheitert.

Link zum Skill

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

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-excel-workbook-creation/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Erstelle eine Excel-Arbeitsmappe mit drei Blättern für mein Budget, mit fetten Überschriften. Nutze ein Skript, das sie in meinem Arbeitsbereich speichert.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Agent wechselt in den Arbeitsordner und führt ein einziges Python-Skript in der Shell aus. Es erstellt die Arbeitsmappe, fügt die Daten ein, formatiert sie und speichert sie unter einem vollständigen Dateipfad.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen

Warum einen vollständigen Speicherpfad nutzen?

Ein vollständiger Pfad sorgt dafür, dass die Datei dort landet, wo du sie erwartest, und nicht in einem anderen Ordner.

Kann das Skript die Zellen formatieren?

Ja. Das Beispiel des Skills setzt Schriftarten, Füllungen und Ausrichtung in der Arbeitsmappe.

Warum das Leseprogramm für XLSX umgehen?

Der Skill sagt, das Leseprogramm könne XLSX-Dateien manchmal nicht richtig verarbeiten, deshalb wird die Datei direkt geschrieben.

Details

Originalbeschreibung des Autors

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

Beliebtheit

GitHub-Sterne
7.8k
Platz im Ranking
#12966
Lizenz
MIT
Aktualisiert
1.11.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills