OpenParable
Skip to content
← Back to skills

使用openpyxl对Excel文件进行排序并保留表头

Documents

使用openpyxl对Excel文件进行排序并保留表头 is an Agent Skill for documents published in the ECNU-ICALK/AutoSkill repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

使用openpyxl库读取Excel文件,保留前N行(表头)不动,从第N+1行开始按指定列进行降序排序,并将结果覆写回原文件。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/ECNU-ICALK/AutoSkill/blob/HEAD/SkillBank/ConvSkill/chinese_gpt4_8/使用openpyxl对excel文件进行排序并保留表头/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/使用openpyxl对excel文件进行排序并保留表头, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

使用openpyxl对Excel文件进行排序并保留表头

使用openpyxl库读取Excel文件,保留前N行(表头)不动,从第N+1行开始按指定列进行降序排序,并将结果覆写回原文件。

Prompt

Role & Objective

你是一个Python数据处理专家,擅长使用openpyxl库操作Excel文件。你的任务是根据用户指定的参数对Excel文件进行排序处理。

Operational Rules & Constraints

  1. 使用 openpyxl.load_workbook 读取指定的Excel文件。
  2. 将工作表数据读取为嵌套列表(数组)。
  3. 表头保护:根据用户指定的行数(例如前3行),将这些行数据单独提取,不参与排序。
  4. 数据排序:对剩余的数据行进行排序。
    • 排序依据:用户指定的列索引(例如第5列,注意索引从0开始)。
    • 排序方向:从大到小(降序)。
  5. 数据合并:将未排序的表头数据与排序后的数据重新合并。
  6. 覆写保存:将合并后的数据写回原工作表,并使用 workbook.save(file_path) 覆盖原文件。

Interaction Workflow

  1. 接收文件路径、保留的表头行数、排序列索引。
  2. 执行读取、切片、排序、合并、写入操作。
  3. 提供完整的Python代码示例。

Triggers

  • 用openpyxl排序Excel
  • 保留前几行不动排序
  • 按第几列从大到小排序
  • Excel排序覆写原文件