मुख्य सामग्री पर जाएँ
Skillpedia
PDF, Word और स्लाइड7.8k · #12875

excel-heredoc-workaround

यह क्या करती है

यह स्किल openpyxl समस्याओं के समय कोड सैंडबॉक्स के बिना Excel वर्कबुक बनाने का तरीका है। यह उन लोगों के लिए है जिन्हें व्यवस्थित हेडर और स्टाइल वाली स्प्रेडशीट चाहिए।

कब इस्तेमाल करें

  • ✓जब openpyxl की समस्या की वजह से सैंडबॉक्स में .xlsx फ़ाइल बनाना विफल हो।
  • ✓जब मुझे स्टाइल वाले हेडर, बॉर्डर और शेड्यूल लेआउट वाली स्प्रेडशीट चाहिए।
  • ✓जब मैं इस कंप्यूटर पर शेल से सीधे Python चला सकता हूँ।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/excel-heredoc-workaround/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“स्टाइल वाले हेडर और बॉर्डर के साथ एक Excel शेड्यूल बनाइए। सैंडबॉक्स विफल हो रहा है, इसलिए कृपया इसे शेल से चलाइए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

AI पहले सैंडबॉक्स आज़माता है, और विफल होने पर शेल से openpyxl स्क्रिप्ट इनलाइन चलाता है, जो वर्कबुक बनाती है, हेडर स्टाइल करती है और फ़ाइल सहेजती है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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
अक्सर पूछे जाने वाले सवाल

क्या पहले सैंडबॉक्स आज़माया जाता है?

हाँ, गाइड कहती है कि पहले सैंडबॉक्स आज़माएँ और सिर्फ़ विफल होने पर बदलें।

कौन सी स्टाइलिंग दिखाई गई है?

उदाहरणों में बोल्ड टेक्स्ट, भराव के रंग, अलाइनमेंट और बॉर्डर शामिल हैं।

सहेजी गई फ़ाइल कैसे मिलती है?

उदाहरण सहेजने के बाद एक पाथ मार्कर छापता है, ताकि आउटपुट फ़ाइल खोजी जा सके।

जानकारी

लेखक का मूल विवरण

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

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#12875
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills