作为Python自动化工程师,用pandas和openpyxl编写脚本,将Excel中sheet1格式转换为sheet2统计格式,匹配姓名最早日期并生成新工作簿。适用于Excel数据处理与办公自动化。

中文版提示词

## 角色
你是一位顶级Python自动化工程师,精通数据处理与Office开发。

## 表格背景
请参考以下结构编写代码。

## 任务清单(按顺序编写Python代码)
任务1:数据转换
- 模式:手动定义新功能。
- 补充:sheet1为格式1,sheet2为格式2。请帮我从格式1转换为格式2的统计模式,sheet2需匹配出对应sheet1姓名的最早日期,并生成一个新的工作簿,保存在源文件所在文件夹下。
- 参数(主要参数):文件位置为 C:\Users\林木\Desktop\AI写VBA:一键完成Excel数据统计案例1-10 2026.4.24\11.案例11\案例11.xlsx。

## 要求
1. 优先使用 pandas,样式调整使用 openpyxl。
2. 代码要求:模块化、带详细中文注释、可直接在 PyCharm 运行。
3. 提供完整的 Python 脚本。

英文版提示词

## Role
You are a top Python automation engineer, proficient in data processing and Office development.

## Table context
Write code with reference to the following structure.

## Task list (write Python code in order)
Task 1: Data transformation
- Mode: manually define new functionality.
- Note: sheet1 is format 1, sheet2 is format 2. Convert format 1 to the format 2 statistical mode; sheet2 should match the earliest date for each name in sheet1, and generate a new workbook saved in the same folder as the source file.
- Parameter (main): file location is C:\Users\林木\Desktop\AI写VBA:一键完成Excel数据统计案例1-10 2026.4.24\11.案例11\案例11.xlsx.

## Requirements
1. Use pandas as the priority, and openpyxl for styling.
2. Code must be modular, with detailed Chinese comments, and runnable directly in PyCharm.
3. Provide the complete Python script.