最近比较苦恼批量修改文件的名字,文件名字还要根据表格对应进行修改,最近刚接触python,所以想到利用python读取excel文件对文件自动化的进行改名,以下就开始进行尝试。
# -*- coding: utf-8 -*-
import xlrd
import os
path_c = ".\\photos"
xlsname = "regulation.xls"
bk = xlrd.open_workbook(xlsname)
#shxrange = range(bk.nsheets)
try:
sh = bk.sheet_by_name("Sheet1")
except:
print "no sheet in %s named Sheet1" % xlsname
nrows = sh.nrows
ncols = sh.ncols
print "nrows %d, ncols %d" % (nrows,ncols)
#cell_value = sh.cell_value(1,1)
#print cell_value
row_list = []
#获取各行数据
for i in range(1,nrows):
row_data = sh.row_values(i)
row_list.append(row_data)
#print row_data
def change_name(filename,regulations):
for i in regulations:
print repr(i[0]) + repr(filename)