Python讀寫Excel檔案的例項
阿新 • • 發佈:2019-02-09
fname = "./excelname.xls"
bk = xlrd.open_workbook(fname)
shxrange = range(bk.nsheets)
try:
#開啟Sheet1工作表
sh = bk.sheet_by_name("Sheet1")
except:
print "no sheet in %s named Sheet1" % fname
#獲取行數
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 = []
#range(起始行,結束行)
for i in range(1,nrows):
row_data = sh.row_values(i)
if row_data[6] == "HXB":
filename = row_data[3]+".apk"
#print "%s %s %s" %(i,row_data[3],filename)
filepath = r"./1/"+filename
print "%s %s %s" %(i,row_data[3],filepath)
if os.path.exists(filepath):
shutil.copy(filepath, r"./myapk/")
bk = xlrd.open_workbook(fname)
shxrange = range(bk.nsheets)
try:
#開啟Sheet1工作表
sh = bk.sheet_by_name("Sheet1")
except:
print "no sheet in %s named Sheet1" % fname
#獲取行數
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 = []
#range(起始行,結束行)
for i in range(1,nrows):
row_data = sh.row_values(i)
if row_data[6] == "HXB":
filename = row_data[3]+".apk"
#print "%s %s %s" %(i,row_data[3],filename)
filepath = r"./1/"+filename
print "%s %s %s" %(i,row_data[3],filepath)
if os.path.exists(filepath):
shutil.copy(filepath, r"./myapk/")