原文来源:
https://blog.csdn.net/sinat_28576553/article/details/81275650
# -*- coding=utf-8 -*-
# 试着读取 xmlx 文件
import openpyxl
# 1: 获取工作对象
workbook = openpyxl.load_workbook("./08xmlx.xlsx")
# 2: 获取所有工作薄
# sheetsName = workbook.get_sheet_names(); # DeprecationWarning: Call to deprecated function get_sheet_names (Use wb.sheetnames). sheetsName = workbook.get_sheet_names();
sheetsName = workbook.sheetnames
print(sheetsName)
# 3: 获取工作表对象 (索引, 或者表名获取)
# worksheet = workbook.get_sheet_by_name("千年等一回") # 利用名字获取表名 # 报警告,弃用消息 DeprecationWarning
# print(worksheet)
# 表名
# worksheet = workbook["千年等一回"] # 根据名字获得工作表
# print(worksheet)
# worksheet = workbook[sheetsName[0]] # 根据索表名引获得工作表
# print(worksheet)
# 索引
worksheet = workbook.worksheets[2] # 根据索引获得工作表
print(worksheet)