Files
YunNanProject/Tools/T3_CheckExcel.py
2025-09-10 10:29:32 +08:00

33 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import openpyxl
from Config.Config import EXCEL_PATH
file_name = EXCEL_PATH
sheetNameArray = ['人口', '毛入学率', '学校数', '班级数', '招生数', '在校生数', '教职工数、专任教师数',
'学校面积、教学辅助房面积']
# 初始化检查状态变量
missing_sheets = []
try:
# 加载工作簿
workbook = openpyxl.load_workbook(file_name, read_only=True)
sheet_names = workbook.sheetnames
workbook.close()
# 检查指定Sheet是否存在
missing_sheets = [sheet for sheet in sheetNameArray if sheet not in sheet_names]
# 输出检查结果
if not missing_sheets:
print("✅ 所有指定Sheet均存在")
else:
print(f"❌ 检查失败:发现{len(missing_sheets)}个缺失Sheet")
print("🔍 缺失列表:")
for sheet in missing_sheets:
print(f" - {sheet}")
except FileNotFoundError:
print(f"🔴 错误Excel文件 '{file_name}' 不存在")
except Exception as e:
print(f"🔴 处理Excel时发生错误{str(e)}")