如何在excel openpyxl python中的工作表之间切换以进行更改 [英] How to switch between sheets in excel openpyxl python to make changes

查看:1154
本文介绍了如何在excel openpyxl python中的工作表之间切换以进行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import openpyxl
wb = openpyxl.load_workbook('D:\excel.xlsx')
wb.get_sheet_names()

在此之后,我可以看到Excel文件具有的工作表(85).现在,我想进入每张工作表,在2-3个单元格中编辑数据(所有工作表都相同),然后保存文件.

After this, i can see the worksheets(85) that the excel file has. Now i want to go into each sheet, edit data in 2-3 cells (which is same for all the sheets) and then save the file.

我对python非常陌生,我需要帮助.谢谢

I am very new to python and i need help. Thanks

推荐答案

在您的情况下,我认为最简单的方法可能是

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]]

其中 n 是工作表编号(第一个为0).将其循环放置,并在要更改工作表时增加 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.

这篇关于如何在excel openpyxl python中的工作表之间切换以进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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