从openpyxl获取工作表名称 [英] getting sheet names from openpyxl

查看:1699
本文介绍了从openpyxl获取工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个较大的xlsx文件(大约14 MB),OpenOffice挂起试图打开它.我正尝试使用 openpyxl 来阅读内容,并遵循

I have a moderately large xlsx file (around 14 MB) and OpenOffice hangs trying to open it. I was trying to use openpyxl to read the content, following this tutorial. The code snippet is as follows:

 from openpyxl import load_workbook
 wb = load_workbook(filename = 'large_file.xlsx', use_iterators = True)
 ws = wb.get_sheet_by_name(name = 'big_data') 

问题是,我不知道工作表名称,并且Sheet1/Sheet2 ..等不起作用(返回NoneType对象).我找不到文档告诉我如何使用openpyxl获取xlsx文件的工作表名称.谁能帮我吗?

The problem is, I don't know the sheet name, and Sheet1/Sheet2.. etc. didn't work (returned NoneType object). I could not find a documentation telling me How to get the sheet names for an xlsx files using openpyxl. Can anyone help me?

推荐答案

使用

工作表名称

sheetnames

返回此工作簿中工作表名称的列表.

Returns the list of the names of worksheets in this workbook.

名称按工作表顺序返回.

Names are returned in the worksheets order.

类型:字符串列表

print (wb.sheetnames)

您还可以从wb.worksheets获取工作表对象:

You can also get worksheet objects from wb.worksheets:

ws = wb.worksheets[0]

这篇关于从openpyxl获取工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆