用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/HKUDS/OpenSpace --skill excel-unmerge-before-write命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Incremental audio production with duration mismatch handling, adaptive stem extension, and pre-mix alignment verification
Audio production with diagnostic analysis, timecode parsing from documents, and verified export workflow
Incremental audio production with duration alignment handling, per-stem verification, and adaptive extension strategies
基于 SOC 职业分类
正在显示 SKILL.md
| name | excel-unmerge-before-write |
| description | Unmerge merged cells in openpyxl worksheets before writing values to avoid AttributeError |
When automating Excel file population with openpyxl, merged cells in templates can cause write failures. This skill provides the pattern to safely handle merged ranges before populating data.
AttributeError when trying to write values to certain cellsBefore writing values to cells in a worksheet, identify and unmerge any overlapping ranges:
from openpyxl import load_workbook
# Load the workbook
wb = load_workbook('template.xlsx')
ws = wb.active
# Unmerge specific ranges before writing
ws.unmerge_cells('A46:C46')
ws.unmerge_cells('E46:F46')
ws.unmerge_cells('I46:K46')
# Now safely write values
ws['A46'] = 'Value 1'
ws['E46'] = 'Value 2'
ws['I46'] = 'Value 3'
wb.save('output.xlsx')
Identify merged ranges in your target worksheet:
print(ws.merged_cells.ranges)
Unmerge relevant ranges before writing any data to those areas:
for merged_range in ws.merged_cells.ranges:
# Optionally filter by area if you only need specific ranges
ws.unmerge_cells(str(merged_range))
Write your data to the now-unmerged cells:
ws.cell(row=46, column=1, value='Your data')
Save the workbook:
wb.save('output.xlsx')
If your workbook has multiple sheets with merged cells:
for sheet_name in wb.sheetnames:
ws = wb[sheet_name]
for merged_range in list(ws.merged_cells.ranges):
ws.unmerge_cells(str(merged_range))
| Error | Cause | Solution |
|---|---|---|
AttributeError on cell write | Writing to merged cell | Call unmerge_cells() first |
KeyError on range | Invalid range string | Use exact range format like 'A1:B2' |
| Data overwrites neighbors | Unmerged too broadly | Unmerge only needed ranges |
unmerge_cells() immediately after loading the worksheet, before any write operationsws.merged_cells.ranges before unmerging if you need to know what was mergedfrom openpyxl import load_workbook
def populate_excel_template(template_path, output_path, data_dict):
"""Populate an Excel template, handling merged cells safely."""
wb = load_workbook(template_path)
ws = wb.active
# Unmerge all cells that might conflict with data writes
for merged_range in list(ws.merged_cells.ranges):
ws.unmerge_cells(str(merged_range))
# Populate data
for cell_ref, value in data_dict.items():
ws[cell_ref] = value
wb.save(output_path)
return output_path