# Excel Format

> |

- **Type:** Skill
- **Install:** `agentstack add skill-yuyy2004-excel-skills-excel-format`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [YuYY2004](https://agentstack.voostack.com/s/yuyy2004)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [YuYY2004](https://github.com/YuYY2004)
- **Source:** https://github.com/YuYY2004/excel-skills/tree/main/claude/skills/excel-format

## Install

```sh
agentstack add skill-yuyy2004-excel-skills-excel-format
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

> This skill follows [[excel-safe-workflow]] four-step method. Must complete Requirement Parsing→Scout before execution, and Verify after.
> 本技能遵循 [[excel-safe-workflow]] 四步法。执行前必须完成 需求解析→勘察，执行后验证。

# Excel Format Adjustment / Excel 格式调整

## 第零步：需求解析

### 自动识别格式需求 / Auto-detect Format Requirements

从用户原话提取所有已明确的格式参数，只追问没说到的。

| 要素 | 常见表述 | 默认值 |
|------|---------|--------|
| **字体** | "微软雅黑""Arial""Times New Roman" | 不改变 |
| **字号** | "12号""10pt""大一点" | 不改变 |
| **加粗** | "加粗""粗体""bold" | 不改变 |
| **斜体** | "斜体""italic" | 不改变 |
| **颜色** | "红色""蓝色""#FF0000" | 不改变 |
| **水平对齐** | "居中""靠左""靠右""两端对齐" | 不改变 |
| **垂直对齐** | "上下居中""顶部对齐""底部对齐" | 不改变 |
| **列宽** | "列宽15""自适应""自动调整宽度" | 不改变 |
| **行高** | "行高20""自适应" | 不改变 |
| **应用范围** | "表头""全部""E列""第2-10行""数据区" | `all`（整表） |

### 解析示例

| 用户说 | 提取 |
|--------|------|
| "表头加粗居中，字体改成微软雅黑 12号" | 范围=表头, 加粗, 水平居中, 字体=微软雅黑, 字号=12 |
| "全部改成 Arial 10号，金额列右对齐" | 范围=全部+金额列, 字体=Arial, 字号=10, 金额列=右对齐 |
| "标题行加粗，数据区垂直居中" | 表头=加粗, 数据区=垂直居中 |
| "列宽全部自适应" | 全部列, 自适应列宽 |
| "把表格美化一下" | 全部, 用默认美化方案 |

### 默认美化方案（用户只说"美化"时启用）/ Default Beautify Preset

| 区域 | 格式 |
|------|------|
| 表头（第1行） | 加粗、水平居中、垂直居中、Arial 10pt |
| 数据区（第2行起） | 垂直居中、Arial 10pt |
| 所有列 | 自适应列宽 |

## 第一步：勘察

```python
import os, sys
sys.stdout.reconfigure(encoding='utf-8')
from openpyxl import load_workbook

FILE = '目标文件.xlsx'

wb = load_workbook(FILE)
ws = wb.active
print(f'工作表: {ws.title}, 行: {ws.max_row}, 列: {ws.max_column}')

# 展示当前样式状态
print('\n=== 当前格式 ===')
for col_idx in range(1, min(ws.max_column + 1, 8)):
    cell = ws.cell(row=1, column=col_idx)
    col_letter = chr(64 + col_idx) if col_idx  127 else 1 for c in str(s))
        max_len = sample.apply(char_width).max()
        # 表头也参与计算
        header_len = char_width(str(col_name))
        max_len = max(max_len, header_len)
        col_letter = get_column_letter(col_idx)
        ws.column_dimensions[col_letter].width = min(max_len + 3, 50)
elif COL_WIDTH is not None:
    from openpyxl.utils import get_column_letter
    for col_idx in cols_to_process:
        ws.column_dimensions[get_column_letter(col_idx)].width = COL_WIDTH

# 行高
if ROW_HEIGHT == 'auto':
    for row in rows_to_process:
        ws.row_dimensions[row].height = None  # Excel 自动计算
elif ROW_HEIGHT is not None:
    for row in rows_to_process:
        ws.row_dimensions[row].height = ROW_HEIGHT

print(f'\n保存中...')
wb.save(FILE)
print(f'完成，耗时 {time.time()-t0:.1f}s')
```

## 第三步：验证

```python
wb = load_workbook(FILE, read_only=True, data_only=True)
ws = wb.active

# 验证表头格式
cell = ws.cell(row=1, column=1)
print(f'表头字体: {cell.font.name}/{cell.font.size}pt')
print(f'表头加粗: {cell.font.bold}')
print(f'表头对齐: {cell.alignment.horizontal}/{cell.alignment.vertical}')

# 验证数据区
cell2 = ws.cell(row=2, column=1)
print(f'数据字体: {cell2.font.name}/{cell2.font.size}pt')

# 验证列宽
if ws.column_dimensions['A'].width:
    print(f'A列宽: {ws.column_dimensions["A"].width}')

wb.close()
print('✅ 验证完成')
```

## 常用预设 / Common Presets

### 专业报表风 / Professional Report
```
FONT_NAME='Arial', FONT_SIZE=10, FONT_BOLD=True(header)
H_ALIGN='center'(header+data), V_ALIGN='center'
COL_WIDTH='auto'
```

### 中文文档风 / Chinese Document
```
FONT_NAME='微软雅黑', FONT_SIZE=11
FONT_BOLD=True(header), H_ALIGN='center'(header)
V_ALIGN='center', COL_WIDTH='auto'
```

### 仅加粗居中表头 / Bold+Center Header Only
```
SCOPE='header', FONT_BOLD=True, H_ALIGN='center', V_ALIGN='center'
```

## 注意事项

1. **列宽自适应**对中文友好（中文字符计 2 宽度），上限 40 字符
2. **字体可用性**取决于 Excel 打开时的系统，Arial/微软雅黑 一般都有
3. **合并单元格**中的格式需单独处理
4. **格式叠加**：None 的参数不会被修改，保留原有格式
5. **操作前必备份**：遵循 [[excel-safe-workflow]] 第零步——操作前自动备份（时间戳命名），成功后保留最新3份，失误后立即删除损坏文件并从备份恢复

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [YuYY2004](https://github.com/YuYY2004)
- **Source:** [YuYY2004/excel-skills](https://github.com/YuYY2004/excel-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-yuyy2004-excel-skills-excel-format
- Seller: https://agentstack.voostack.com/s/yuyy2004
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
