agentleFS
Marnie0415Marnie0415/pi-skills/xlsx-processing/SKILL.md

xlsx-processing

Skill1 starsChanged 5 months agoMITView on GitHub

Create, read, and modify Microsoft Excel (.xlsx) spreadsheets. Use when the user needs to generate reports, analyze tabular data, edit spreadsheets programmatically, or convert data to/from Excel format.

  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

XLSX 电子表格处理 Skill

在 Termux Android 上使用纯 JS 或 Python 工具处理 .xlsx 文件。

可用工具

方案 A: xlsx (SheetJS, Node.js, 推荐)

npm install xlsx

适用于:创建、读取、修改、公式、样式

方案 B: openpyxl (Python)

pip install openpyxl

适用于:复杂样式、图表、条件格式

常见操作 (Node.js + SheetJS)

1. 创建新的 XLSX 文件

import * as XLSX from 'xlsx'

const wb = XLSX.utils.book_new()
const data = [
  ['姓名', '年龄', '城市'],
  ['张三', 28, '北京'],
  ['李四', 32, '上海'],
]
const ws = XLSX.utils.aoa_to_sheet(data)
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
XLSX.writeFile(wb, 'output.xlsx')

2. 读取 JSON 数据源生成表格

const jsonData = [
  { name: '张三', score: 95 },
  { name: '李四', score: 87 },
]
const ws = XLSX.utils.json_to_sheet(jsonData)
const wb = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(wb, ws, '成绩')
XLSX.writeFile(wb, 'grades.xlsx')

3. 读取并解析

const wb = XLSX.readFile('input.xlsx')
const ws = wb.Sheets[wb.SheetNames[0]]
const data = XLSX.utils.sheet_to_json(ws)  // 返回对象数组
const matrix = XLSX.utils.sheet_to_json(ws, { header: 1 })  // 返回二维数组

4. 修改现有文件

const wb = XLSX.readFile('report.xlsx')
const ws = wb.Sheets['Sheet1']
XLSX.utils.sheet_add_aoa(ws, [['新数据', 100]], { origin: 'A5' })
XLSX.writeFile(wb, 'report_modified.xlsx')

常见操作 (Python + openpyxl)

创建带样式的工作簿

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

wb = Workbook()
ws = wb.active
ws.title = "数据"

# 表头样式
header_font = Font(bold=True, color="FFFFFF")
header_fill = PatternFill(start_color="4472C4", end_color="4472C4", fill_type="solid")
ws['A1'] = '姓名'; ws['B1'] = '分数'
for cell in ws[1]:
    cell.font = header_font
    cell.fill = header_fill

ws.append(['张三', 95])
ws.append(['李四', 87])
wb.save('styled.xlsx')

格式 / 数据处理注意

场景方法
读取日期XLSX.readFile 时设 { cellDates: true }
处理公式sheet_to_json 用 { raw: false } 取值
列宽自动调整手动计算最大字符宽度后设置 ws['!cols']
合并单元格openpyxl: ws.merge_cells('A1:C1')
过滤器 / 冻结openpyxl: ws.auto_filter.ref, ws.freeze_panes

注意事项

  • 📐 SheetJS (xlsx) 不支持保留样式;读取再写出会丢失颜色/字体
  • ⚠️ 需要保留样式的修改,使用 openpyxl 操作
  • 📏 大文件 (>5MB) 优先用 openpyxl 的 read_only=True 模式
  • 🔄 中文编码自动处理,无需额外设置
  • 💾 操作前先备份原文件

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.