到目前为止,这是我的代码:
import os
import openpyxl
os.chdir('C:\\Python34\\MyPy')
wb=openpyxl.load_workbook('example.xlsx')
wb.get_sheet_names()
但是我得到了这些错误:
Warning (from warnings module):
/File "main", line 1
DeprecationWarning: Call to deprecated function get_sheet_names (Use wb.sheetnames).
['Sheet1', 'Sheet2', 'Sheet3']
最佳答案
警告不是错误 - 它们不会妨碍您的程序运行。如果出现已弃用警告
:您使用的功能将在未来版本中删除,因此开发人员将其标记为已弃用。
它现在可能可以工作,但下一个版本可能不再有效,因为此功能已被删除 - 然后您将收到错误消息。
你可以这样修复它:
wb.sheetnames # all names sheet = wb["UseThisSheet"] # select a certain sheet by name for sheet2 in wb: # or go over all sheets print(sheet2.title) sh = wb.active # normally sheet at index 0 if you create an empy one
Source: https://openpyxl.readthedocs.io/en/stable/tutorial.html
这是一个关于如何创建工作簿的简短示例(我对其他一些 xlsx 问题的回答):https://stackoverflow.com/a/48782382/7505395
关于Python - 'get_sheet_by_name' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159245/