'commit'
This commit is contained in:
32
Tools/T3_CheckExcel.py
Normal file
32
Tools/T3_CheckExcel.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
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)}")
|
Reference in New Issue
Block a user