如何使用 openpyxl 获取 excel 工作簿的第一个 sheet?

How to get the first sheet of an excel workbook using openpyxl?

我可以使用 wb["sheet_name"] 方法获得所需的 sheet,但我想获得第一个,或者说第 n 个 sheet,不管名字.

wb = load_workbook(filename = xlsx_dir)   # xlsx_dir is the workbook path

ws = wb["Details"]   # Details is the sheet name

您需要使用工作簿对象worksheets属性

ws = wb.worksheets[0]

您需要使用工作表函数sheet_by_name

sheet =  wb.sheet_by_name("Details")