This commit is contained in:
2025-09-10 10:24:00 +08:00
parent a15c6c1767
commit 5be4a8458f
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# 读取 Doc目录 数据库-2015-2024-v2.xlsx 文件内容
# pip install openpyxl
import openpyxl
from Config.Config import EXCEL_PATH
from Util.AreaUtil import query_area_info
file_name = EXCEL_PATH
# 读取Excel文件并获取所有sheet名称
try:
# 加载工作簿
workbook = openpyxl.load_workbook(file_name, read_only=True)
sheet_names = workbook.sheetnames
if sheet_names:
first_sheet = workbook[sheet_names[0]]
# 读取所有行数据
rows = list(first_sheet.iter_rows(values_only=True))
# 跳过前两行表头,从第三行开始处理数据
for row_num, row in enumerate(rows[2:], start=3):
# 假设行政区划名称在第一列索引0
if row and row[0]:
area_name = row[0]
result = query_area_info(area_name)
if result:
print(
f"{row_num}: {area_name} -> 全称: {result['full_name']}, 行政区划码: {result['area_code']}")
else:
print(f"{row_num}: 未找到 '{area_name}' 的相关信息")
workbook.close()
except FileNotFoundError:
print(f"错误:找不到文件 '{file_name}'")
except Exception as e:
print(f"读取Excel时发生错误{str(e)}")