Excel Heredoc Fallback logo

Excel Heredoc Fallback

OrganizationPopular
HKUDS
excel-heredoc-fallback

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

Overview

PublisherHKUDS
RepositoryOpenSpace
Skill nameexcel-heredoc-fallback
Stars
7.7K
Forks
918
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by HKUDS on GitHub. Read the source before you install it.

Installation

Install the Excel Heredoc Fallback AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HKUDS/OpenSpace.git /tmp/OpenSpace
mkdir -p .claude/skills
cp -r /tmp/OpenSpace/benchmarks/gdpval/skills/excel-heredoc-fallback .claude/skills/excel-heredoc-fallback
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Excel Heredoc Fallback in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Excel Heredoc Fallback on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Excel Heredoc Fallback is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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:

python
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:

bash
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:

python
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:

python
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

python
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

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

Merged Cells

python
ws.merge_cells('A1:C1')
ws['A1'] = 'Merged Header'
ws['A1'].alignment = Alignment(horizontal='center')

Multiple Sheets

python
wb.create_sheet(title='Summary')
wb.create_sheet(title='Details')
ws_summary = wb['Summary']
ws_details = wb['Details']

Troubleshooting

IssueSolution
openpyxl not foundAdd pip install openpyxl before Python script
File not createdCheck working directory, use absolute paths
Permission deniedEnsure write permissions in target directory
Encoding issuesPython 3 handles UTF-8 by default; specify if needed
Large files time outIncrease run_shell timeout parameter

Comparison: Sandbox vs. Shell Heredoc

Aspectexecute_code_sandboxrun_shell heredoc
PreferredYes (cleaner)No (fallback)
DependenciesMay be restrictedUses system Python
File accessSandboxedFull filesystem
Styling supportSometimes limitedFull support
DebuggingLogs in tool outputFull stdout/stderr

Example Complete Workflow

# Step 1: Try sandbox
tool: execute_code_sandbox
code: |
  from openpyxl import Workbook
  wb = Workbook()
  ws = wb.active
  ws['A1'] = 'Test'
  wb.save('test.xlsx')

# Step 2: If that fails, use shell heredoc
tool: run_shell
command: |
  python3 << 'EOF'
  from openpyxl import Workbook
  from openpyxl.styles import Font, PatternFill
  
  wb = Workbook()
  ws = wb.active
  
  ws['A1'] = 'Header'
  ws['A1'].font = Font(bold=True)
  ws['A1'].fill = PatternFill(start_color='FFFF00', fill_type='solid')
  
  wb.save('test.xlsx')
  print("Created: test.xlsx")
  EOF

# Step 3: Verify
tool: run_shell
command: ls -lh test.xlsx

Frequently asked questions

What does the Excel Heredoc Fallback AI skill do?

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

Why use Excel Heredoc Fallback on TypingMind?

Because you install it once and use it with any model. Excel Heredoc Fallback is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Excel Heredoc Fallback in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/HKUDS/OpenSpace/tree/main/benchmarks/gdpval/skills/excel-heredoc-fallback. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Excel Heredoc Fallback?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Excel Heredoc Fallback?

As many as you like. As long as a model supports skills, you can use Excel Heredoc Fallback with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Excel Heredoc Fallback AI skill free?

Yes. It is published on GitHub by HKUDS under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇