Excel Heredoc Workaround logo

Excel Heredoc Workaround

OrganizationPopular
HKUDS
excel-heredoc-workaround

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

Overview

PublisherHKUDS
RepositoryOpenSpace
Skill nameexcel-heredoc-workaround
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 Workaround 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-workaround .claude/skills/excel-heredoc-workaround
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Excel Heredoc Workaround 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 Workaround 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 Workaround 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 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:

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

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

bash
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

Aspectexecute_code_sandboxrun_shell heredoc
ReliabilityMay fail with openpyxlMore stable execution
Styling supportLimitedFull openpyxl support
File outputVia ARTIFACT_PATHDirect file write
DebuggingLimited outputFull stdout/stderr

Common Styling Patterns

Bold Headers with Colored Background

python
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

python
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

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

Issue: Styling not appearing

  • Fix: Ensure you save the workbook after applying all styles

Example Complete Workflow

bash
# Create Excel with full styling
python3 << 'EOF'
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill, Border, Side

wb = Workbook()
ws = wb.active
ws.title = "Report"

# Header row
headers = ["ID", "Name", "Value", "Date"]
for col, h in enumerate(headers, 1):
    cell = ws.cell(row=1, column=col, value=h)
    cell.font = Font(bold=True, color="FFFFFF")
    cell.fill = PatternFill(start_color="2F5597", fill_type="solid")
    cell.alignment = Alignment(horizontal="center")

# Data
ws.append([1, "Item A", 100, "2024-01-01"])
ws.append([2, "Item B", 200, "2024-01-02"])

# Apply borders
thin = Side(style='thin')
border = Border(left=thin, right=thin, top=thin, bottom=thin)
for row in ws.iter_rows():
    for cell in row:
        cell.border = border

# Auto-width columns
for col in ws.columns:
    col_letter = col[0].column_letter
    max_len = max(len(str(cell.value)) if cell.value else 0 for cell in col)
    ws.column_dimensions[col_letter].width = min(max_len + 2, 50)

wb.save("Report.xlsx")
print("Success: Report.xlsx created")
EOF

Frequently asked questions

What does the Excel Heredoc Workaround AI skill do?

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

Why use Excel Heredoc Workaround on TypingMind?

Because you install it once and use it with any model. Excel Heredoc Workaround 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 Workaround in TypingMind?

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

Which AI models can use Excel Heredoc Workaround?

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 Workaround?

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

Is the Excel Heredoc Workaround 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 👇