How to switch between sheets in excel openpyxl python to make changes

给你一囗甜甜゛ 提交于 2019-12-07 04:54:37

In your case I see the easiest is probably

import openpyxl

n = 0
wb = openpyxl.load_workbook('D:\excel.xlsx')
sheets = wb.sheetnames
ws = wb[sheets[n]]

Where n is the sheetnumber (0 is the first). Put that in a loop and increase n when you want to change the sheet.

I hope below code will be help. When mentioning the path use front slash rather than back slash.

Get All Sheet Name. Find sheetwise max row and column in particular sheet

import openpyxl
workBook = load_workbook(filename='D:/excel.xlsx')
sheets = workBook.sheetnames
i=1
for s_name in sheets:
    print(s_name)
    sheet=workBook[s_name]
    m_row=sheet.max_row
    m_col=sheet.max_column
    print(m_row)
    print(m_col)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!