Aller au contenu
Skillpedia
PDF, Word et présentations7.8k · #12875

excel-heredoc-workaround

Ce qu’il fait

Ce skill est une solution de contournement pour créer des classeurs Excel avec openpyxl lorsque le bac à sable de code rencontre des problèmes. Il s'adresse aux personnes qui ont besoin de feuilles de calcul avec des en-têtes structurés et un style soigné.

Quand l’utiliser

  • ✓Quand la création d'un fichier .xlsx échoue dans le bac à sable à cause de problèmes avec openpyxl.
  • ✓Quand j'ai besoin d'une feuille de calcul avec des en-têtes stylisés, des bordures et une présentation de planning.
  • ✓Quand je peux lancer Python directement depuis le shell sur cet ordinateur.

Lien du skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/excel-heredoc-workaround/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/excel-heredoc-workaround/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Crée un planning Excel avec des en-têtes stylisés et des bordures. Le bac à sable échoue, alors lance-le depuis le shell.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'IA tente d'abord le bac à sable, et en cas d'échec exécute un script openpyxl directement dans le shell : elle crée le classeur, met en forme les en-têtes et enregistre le fichier.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

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 .xlsx files with openpyxl
  • execute_code_sandbox fails 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 openpyxl before running her
Questions fréquentes

Le bac à sable est-il essayé en premier ?

Oui, le guide demande d'essayer le bac à sable d'abord et de ne passer à une autre méthode qu'en cas d'échec.

Quelle mise en forme est montrée ?

Les exemples incluent le texte en gras, les remplissages, l'alignement et les bordures.

Comment retrouver le fichier enregistré ?

L'exemple affiche un repère de chemin après l'enregistrement, ce qui permet de localiser le fichier produit.

Détails

Description originale de l’auteur

Create Excel files with openpyxl by falling back to run_shell with inline Python heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

Popularité

Étoiles GitHub
7.8k
Position au classement
#12875
Licence
MIT
Mis à jour
01/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires