You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.5 KiB
66 lines
2.5 KiB
import pandas as pd
|
|
from openpyxl import load_workbook
|
|
from openpyxl.styles import PatternFill
|
|
from openpyxl.formatting.rule import ColorScaleRule
|
|
|
|
# ================= 创建测试数据 =================
|
|
project_data = {
|
|
"项目编号": ["P001", "P002"],
|
|
"项目名称": ["CRM系统升级", "电商平台开发"],
|
|
"项目类型": ["升级", "新开发"],
|
|
"起止时间": ["2025-03-01 ~ 2025-06-30", "2025-04-01 ~ 2025-12-31"],
|
|
"当前阶段": ["开发中", "需求确认"],
|
|
"交付状态": ["未交付", "部分交付"]
|
|
}
|
|
|
|
progress_data = {
|
|
"项目编号": ["P001", "P002"],
|
|
"整体进度(%)": [45, 20],
|
|
"剩余人天": [120, 300],
|
|
"当前人数": [8, 5],
|
|
"资源缺口": [2, 3]
|
|
}
|
|
|
|
maintenance_data = {
|
|
"产品名称": ["CRM系统", "订单管理模块"],
|
|
"维护类型": ["付费维护", "质保期维护"],
|
|
"工单量": [15, 8],
|
|
"平均耗时(h)": [3.5, 2.0]
|
|
}
|
|
|
|
product_data = {
|
|
"产品名称": ["CRM标准版", "ERP基础版"],
|
|
"定价(万元)": [12.8, 28.5],
|
|
"近半年销量": [35, 18]
|
|
}
|
|
|
|
# ================= 生成Excel文件 =================
|
|
with pd.ExcelWriter("部门项目总览.xlsx", engine="openpyxl") as writer:
|
|
# 生成四个工作表
|
|
pd.DataFrame(project_data).to_excel(writer, sheet_name="项目概况", index=False)
|
|
pd.DataFrame(progress_data).to_excel(writer, sheet_name="进度管理", index=False)
|
|
pd.DataFrame(maintenance_data).to_excel(writer, sheet_name="维护工作", index=False)
|
|
pd.DataFrame(product_data).to_excel(writer, sheet_name="产品信息", index=False)
|
|
|
|
# 获取工作簿对象进行格式设置
|
|
workbook = writer.book
|
|
|
|
# 设置公共格式
|
|
for sheetname in writer.sheets:
|
|
sheet = writer.sheets[sheetname]
|
|
# 冻结首行
|
|
sheet.freeze_panes = "A2"
|
|
# 设置列宽
|
|
sheet.column_dimensions['A'].width = 15
|
|
sheet.column_dimensions['B'].width = 25
|
|
|
|
# 为进度表添加条件格式
|
|
progress_sheet = writer.sheets["进度管理"]
|
|
progress_rule = ColorScaleRule(start_type='num', start_value=0, start_color='FF0000',
|
|
mid_type='num', mid_value=50, mid_color='FFFF00',
|
|
end_type='num', end_value=100, end_color='00FF00')
|
|
progress_sheet.conditional_formatting.add("B2:B100", progress_rule)
|
|
|
|
# ================= 最终文件生成 =================
|
|
print("文件已生成:部门项目总览.xlsx")
|