Files
YunNanProject/Tools/GetJson.py
2025-09-10 09:27:40 +08:00

23 lines
738 B
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.

# 读取 Doc目录 数据库-2015-2024-v2.xlsx 文件内容
# pip install openpyxl
import openpyxl
file_name=r'D:\dsWork\YunNanProject\Doc\数据库-2015-2024-v2.xlsx'
# 读取Excel文件并获取所有sheet名称
try:
# 加载工作簿(添加密码参数)
workbook = openpyxl.load_workbook(file_name, read_only=True)
sheet_names = workbook.sheetnames
print("Excel中的sheet名称列表")
for idx, sheet in enumerate(sheet_names, 1):
print(f"{idx}. {sheet}")
# 关闭工作簿释放资源
workbook.close()
except FileNotFoundError:
print(f"错误:找不到文件 '{file_name}'")
except Exception as e:
print(f"读取Excel时发生错误{str(e)}")