需求:需要将excel内文件名所对应的修改应用到实际文件中。
思路:
1、读取文件的名字
2、打开excel
3、将文件名与excel内文件名做循环匹配
4、匹配上后,读取相邻单元格所需修改的数据
5、然后改名,保存。
先上结果:
然后上代码:
import os
import xlwt
import xlrd
datas=os.listdir('G:/test folder')excel_xuhao=xlrd.open_workbook('G:/untitled3/Exce1表.xls')
sheet_xuhao=excel_xuhao.sheet_by_index(0)
rows = sheet_xuhao.nrows
for data in datas:
# name=data.split(".")[0]
name=data
print(name)
for row in range(rows):
if name == sheet_xuhao.cell(row,0).value:
xuhao=s