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

excel-heredoc-fallback

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

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

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

  • ✓जब सैंडबॉक्स openpyxl इम्पोर्ट एरर या अनुमति की समस्या से विफल हो।
  • ✓जब फ़ाइल में Excel फ़ॉर्मेटिंग, रंग, मर्ज की हुई सेल या फ़ॉर्मूले चाहिए।
  • ✓जब उसी स्प्रेडशीट के काम पर सैंडबॉक्स कई बार विफल हो चुका हो।

Skill का लिंक

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

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

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

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

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

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

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

“रंग वाले हेडर और फ़ॉर्मूले वाला कुल योग बनाकर एक Excel फ़ाइल दीजिए। सैंडबॉक्स बार-बार विफल हो रहा है, इसलिए इसे किसी और तरीके से चलाइए।”

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

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

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

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

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Excel Creation via Shell Heredoc Fallback

Overview

When creating Excel files with openpyxl, execute_code_sandbox may fail due to sandbox restrictions, missing dependencies, or permission issues. This skill provides a reliable fallback: execute Python code via run_shell using an inline heredoc script. This approach often succeeds where the sandbox fails and supports full openpyxl features including styling, formulas, and formatting.

When to Use This Skill

  • execute_code_sandbox fails when importing or using openpyxl
  • Sandbox shows errors about missing packages, permissions, or execution restrictions
  • You need to create Excel files with advanced formatting (styles, colors, merged cells, formulas)
  • Previous sandbox attempts have failed multiple times

Step-by-Step Instructions

Step 1: Attempt Sandbox Execution First

Always try execute_code_sandbox first, as it's cleaner and preferred when it works:

from openpyxl import Workbook
from openpyxl.styles import Font, Fill, PatternFill, Alignment

wb = Workbook()
ws = wb.active
ws['A1'] = 'Header'
ws['A1'].font = Font(bold=True)
wb.save('output.xlsx')

Step 2: Detect Sandbox Failure

Watch for these failure indicators:

  • ImportError for openpyxl or related modules
  • Permission denied errors
  • File write failures
  • Repeated retry loops without success
  • Timeout or resource errors

Step 3: Fall Back to Shell Heredoc

When sandbox fails, switch to run_shell with a Python heredoc:

python3 << 'EOF'
from openpyxl import Workbook
from openpyxl.styles import Font, Fill, PatternFill, Alignment, Border, Side

# Create workbook
wb = Workbook()
ws = wb.active
ws.title = "Sheet1"

# Add data with formatting
ws['A1'] = 'Name'
ws['B1'] = 'Value'
ws['A1'].font = Font(bold=True, size=14)
ws['B1'].font = Font(bold=True, size=14)

# Add rows
data = [
    ['Item 1', 100],
    ['Item 2', 200],
    ['Item 3', 150],
]

for row_idx, row_data in enumerate(data, start=2):
    for col_idx, value in enumerate(row_data, start=1):
        cell = ws.cell(row=row_idx, column=col_idx, value=value)
        cell.alignment = Alignment(horizontal='center')

# Add formulas if needed
ws['B5'] = '=SUM(B2:B4)'

# Save the file
wb.save('output.xlsx')
print("Excel file created successfully: output.xlsx")
EOF

Step 4: Use run_shell Tool

Execute the heredoc via run_shell:

tool: run_shell
command: python3 << 'EOF'
[from openpyxl code here]
EOF

Step 5: Verify File Creation

After execution, confirm the file was created:

tool: run_shell
command: ls -lh output.xlsx

Check the file size to ensure it's not empty (should be >1KB for typical spreadsheets).

Best Practices

1. Use Single-Quoted Heredoc Delimiter

Always use << 'EOF' (with quotes) to prevent shell variable expansion inside the Python code.

2. Include Error Handling

Add try/except blocks to catch and report issues:

try:
    from openpyxl import Workbook
    # ... your code ...
    wb.save('output.xlsx')
    print("SUCCESS: File created")
except Exception as e:
    print(f"ERROR: {e}")
    exit(1)

3. Print Confirmation Messages

Always include print statements that confirm success or report specific errors. This helps debug issues.

4. Use Absolute or Explicit Paths

When saving files, use explicit paths to avoid confusion:

wb.save('./output.xlsx')  # Explicit current directory
# or
wb.save('/workspace/output.xlsx')  # Absolute path

5. Keep Scripts Concise

Heredoc scripts should be focused and not excessively long. If the Excel logic is complex, consider writing a separate .py file first using write_file, then executing it.

Advanced Formatting Examples

Cell Styling

from openpyxl.styles import Font, PatternFill, Alignment, Border, Side

# Define styles
bold_font = Font(bold=True, size=12)
header_fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')
center_align = Alignment(horizontal='center', vertical='center')
thin_border = Border(
    left=Side(style='thin'),
    right=Side(style='thin'),
    top=Side(style='thin'),
    bottom=Side(style='thin')
)

# Apply to cells
ws['A1'].font = bold_font
ws['A1'].fill = header_fill
ws['A1'].alignment = center_align

Column Width and Row Height

ws.column_dimensions['A'].width = 20
ws.column_dimensions['B'].width = 15
ws.row_dimensions[1].height = 25

Merged Cells

ws.merge_cells('A1:C1'
अक्सर पूछे जाने वाले सवाल

heredoc क्या है?

यह एक ही शेल कमांड में कई पंक्तियों का कोड देने का तरीका है।

कौन सी विफलताएँ बदलाव को ट्रिगर करती हैं?

गाइड में इम्पोर्ट एरर, अनुमति से इनकार, लिखने की विफलता, बार-बार की कोशिशें और टाइम आउट शामिल हैं।

क्या इसमें फ़ॉर्मूले जोड़े जा सकते हैं?

हाँ, गाइड कहती है कि openpyxl की पूरी सुविधाएँ, जैसे फ़ॉर्मूले और स्टाइलिंग, समर्थित हैं।

जानकारी

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

Create Excel files with openpyxl by falling back to shell-based Python heredoc when sandbox execution fails

repo: HKUDS/AgentPilot

लोकप्रियता

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

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

0

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

कमेंट

  • …

इस repository की और skills

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