【发布时间】:2021-10-16 15:50:40
【问题描述】:
在一个文件夹中,我有 50 个 excel 文件,每个文件中有多个工作表。我必须更新这些文件中工作表的名称,其中 sheet_name 包含“XYZ”。
因此,对于每个文件,如果 sheet_name 具有“XYZ”,则将该 sheet_name 更改为“ABC”。我尝试使用以下代码遍历文件,但无法编写代码来更改工作表名称:
filelist=[]
for path, subdirs, files in os.walk(directory):
for file in files:
if (file.endswith('.xlsx') or file.endswith('.xls') or file.endswith('.XLS')):
filelist.append(os.path.join(path, file))
【问题讨论】:
标签: python python-3.x pandas dataframe python-2.7