# 获取所有的工作表名称
import openpyxl
wb = openpyxl.load_workbook('my excel.xlsx')
# 获取所有的工作表名称
print(wb.sheetnames)
# 获取当前激活的工作表
print(wb.active.title)
# 通过工作簿获取
for s in wb:
print(s.title)
sheet=wb['Sheet1']
print(sheet)
ws = wb.active #返回的是工作表对象
rows = ws[2]
# 遍历所有单元格
for r in rows:
print(r.value, end='\t')
row=sheet['2']
row_date=[]
for cell in row:
row_date.append(cell.value)
print(row_date)
#读取第四行的内容
rows = ws[4]
# 遍历所有单元格
for r in rows:
print(r.value, end='\n')
#读取二列的内容
columns = ws['B']
for c in columns:
print(c.value, end='\t')