返回顶部
a

automate-excelExcel自动化

Automates reading, writing, merging, transforming, and validating Excel (.xlsx/.xls) files. Use when the user works with spreadsheets, .xlsx files, Excel data, CSV-to-Excel conversion, batch Excel processing, or report generation from tables.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.3
安全检测
已通过
4,361
下载量
免费
免费
3
收藏
概述
安装方式
版本历史

automate-excel

Excel 自动化处理

在用户需要处理 Excel 文件、表格数据、批量转换或报表生成时应用本 skill。

你想做的事调用的脚本典型参数
多个 Excel 或多个 sheet 合成一张表mergesheets.py--inputs 文件或目录 --output out.xlsx
把某 sheet 导出成 CSV
excelto_csv.py | --input file.xlsx --output file.csv | | 把 CSV 转成 Excel | csvtoexcel.py | --input a.csv --output a.xlsx 或 --inputs a.csv b.csv | | 按条件筛选行(等于/大于/包含) | filter_excel.py | --where 列名=值 或 列名>100、列名~北京 | | 按行数拆成多个文件,或按某列取值拆分 | split_excel.py | --by-rows 5000 或 --by-column 地区 | | 按某列去重 | deduplicate_excel.py | --keys 编号 --keep first/last | | 按列分组并求和/计数/平均 | aggregate_excel.py | --group-by 地区 --agg 销售额:sum | | 检查必须列、重复键、空行 | validate_excel.py | --require-cols 列名 --key-cols 列名 | | 只保留/重命名部分列 | select_columns.py | --columns 列1,列2 --rename 旧:新 | | 两个表按一列对齐合并(VLOOKUP) | merge_tables.py | --left a.xlsx --right b.xlsx --on 键列 | | 主表依次跟多个表做 VLOOKUP | vlookup_multi.py | --main 主.xlsx --lookups 表1.xlsx:键列 表2.xlsx:键列 | | 行列转置 | transpose_excel.py | --input in.xlsx --output out.xlsx | | 用数据表按行填模板里的 {{列名}} | template_fill.py | --template t.xlsx --data d.csv --output out.xlsx | | 重命名工作表 | renamesheets.py | --rename Sheet1:新名 或 --prefix 2024 | | 条件格式(大于/小于/重复值/色阶) | format_conditional.py | --column C --rule gt --value 100 --fill red | | 某列当文本显示,避免科学计数法 | formatcolumnsas_text.py | --columns 身份证号,订单号 |

本地直接运行:进入本 skill 所在目录(或把 scripts/ 加入路径),先 pip install -r scripts/requirements.txt,再执行 python scripts/脚本名.py --help 看参数,或按上表传参运行。

技术栈

  • - 读写 .xlsx:openpyxl(保留格式、公式、多工作表)
  • 数据分析/透视:pandas + openpyxl 引擎
  • 旧格式 .xls:xlrd(只读)

优先用 openpyxl 做单元格级操作和格式保留;需要筛选、聚合、合并多表时用 pandas。

依赖

bash
pip install openpyxl pandas xlrd

或使用 skill 自带:pip install -r scripts/requirements.txt

通用流程

  1. 1. 确认输入:文件路径、工作表名或索引、是否有表头、编码(CSV 时)。
  2. 读取:用 openpyxl 或 pandas 按需读取整表/区域。
  3. 处理:按用户需求转换、过滤、合并、计算。
  4. 写出:指定输出路径与格式(.xlsx/.csv);必要时保留原格式或新建工作簿。
  5. 校验:检查行数、关键列、重复值或业务规则。

读取 Excel

整表为 list of dict(保留表头):

python
import openpyxl

wb = openpyxl.loadworkbook(input.xlsx, readonly=True, data_only=True)
ws = wb.active # 或 wb[Sheet1]
rows = list(ws.iterrows(minrow=1, values_only=True))
header = rows[0]
data = [dict(zip(header, row)) for row in rows[1:]]
wb.close()

用 pandas(适合分析、过滤、合并):

python
import pandas as pd

df = pd.readexcel(input.xlsx, sheetname=0, engine=openpyxl)

sheet_name 可为 0、Sheet1 或 [0, 1] 多表

指定区域:

python

openpyxl


for row in ws[A1:D10]:
...

pandas

df = pd.read_excel(input.xlsx, usecols=A:D, header=0, nrows=100)

写入 Excel

新建并写入(openpyxl):

python
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment

wb = Workbook()
ws = wb.active
ws.title = 结果
ws.append([列A, 列B, 列C])
for row in data_rows:
ws.append(row)
ws[A1].font = Font(bold=True)
wb.save(output.xlsx)

用 pandas 写出多表:

python
with pd.ExcelWriter(output.xlsx, engine=openpyxl) as writer:
df1.toexcel(writer, sheetname=汇总, index=False)
df2.toexcel(writer, sheetname=明细, index=False)

追加到已有文件(先加载再写):

python
wb = openpyxl.load_workbook(existing.xlsx)
ws = wb[Sheet1]
for row in new_rows:
ws.append(row)
wb.save(existing.xlsx)

常见任务速查

任务做法
多文件合并mergesheets.py 或 pandas readexcel + pd.concat + toexcel。
CSV ↔ Excel
exceltocsv.py / csvto_excel.py 或 pandas 读写。 | | 按条件筛选 | filter_excel.py 或 df[df[列] == 值] / df.query()。 | | 按行/按列拆分 | split_excel.py(按行数或按某列取值分文件)。 | | 去重 | deduplicateexcel.py 或 df.dropduplicates(subset=[列], keep=first)。 | | 按列聚合 | aggregate_excel.py 或 df.groupby(列).agg({数值列: sum})。 | | 校验 | validate_excel.py。 | | 选择/重命名列 | select_columns.py。 | | 两表按键合并 | merge_tables.py(left/inner/outer)。 | | 行列转置 | transpose_excel.py。 | | 模板填充 | template_fill.py({{列名}} 占位符)。 | | 重命名 sheet | rename_sheets.py。 | | 多表 VLOOKUP | vlookup_multi.py(主表 + 多个查找表依次左连接)。 | | 条件格式 | format_conditional.py(大于/小于/介于/重复值/色阶)。 | | 列格式为文本 | formatcolumnsas_text.py(避免长数字科学计数法)。 | | 保留原格式写数据 | 用 openpyxl 加载原文件,只改写目标单元格,再 save。 |

批量处理

当用户需要处理目录下多个 Excel 时:

  1. 1. 用 pathlib.Path(目录).glob(*.xlsx) 枚举文件。
  2. 对每个文件读取 → 处理 → 可汇总到一个 DataFrame 或分别写出。
  3. 输出可为一个合并文件,或 原名_out.xlsx 等约定;在 SKILL 中明确输出命名规则。
  4. 出错时记录文件名和异常,继续处理其余文件,最后汇总报错列表。

校验与错误处理

  • - 读取前用 Path(file).exists() 检查文件存在。
  • 表为空或缺少预期列时给出明确提示(列名/行数)。
  • 写入前若目标文件已存在,按用户要求覆盖或换名;大文件考虑 write

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 automate-excel-1776202622 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 automate-excel-1776202622 技能

通过命令行安装

skillhub install automate-excel-1776202622

下载

⬇ 下载 automate-excel v0.1.3(免费)

文件大小: 31.66 KB | 发布时间: 2026-4-15 11:22

v0.1.3 最新 2026-4-15 11:22
Initial public release with a comprehensive toolkit of Excel and CSV batch automation scripts.

- Added 18+ command line scripts for Excel/CSV tasks: merging, conversion, deduplication, filtering, aggregation, validation, splitting, VLOOKUP, renaming sheets, formatting, and template fill.
- Provided ready-to-use code samples and detailed usage guides in SKILL.md.
- Included requirements.txt for easy dependency installation.
- All scripts operate independently and support command line arguments for flexible batch processing.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部