import xlrd,xlsxwriter
allxls=["/Users/xubin/myapp/pythonfile/第一个测试文件.xlsx","/Users/xubin/myapp/pythonfile/第二个测试文件.xlsx","/Users/xubin/myapp/pythonfile/第三个测试文件.xlsx"]
endxls ="/Users/xubin/myapp/pythonfile/endxls.xlsx"
def open_xls(file):
try:
fh=xlrd.open_workbook(file)
return fh
except Exception as e:
print(str("打开出错,错误为:"+e))
def getsheet(fh):
return fh.sheets()
def getnrows(fh,sheet):
table=fh.sheets()[sheet]
content=table.nrows
return content
def getfilect(fh,fl,shnum):
fh=open_xls(fl)
table=fh.sheet_by_name(shname[shnum])
num=getnrows(fh,shnum)
lenrvalue=len(rvalue)
for row in range(0,num):
rdata=table.row_values(row)
rvalue.append(rdata)
print(rvalue[lenrvalue:])
filevalue.append(rvalue[lenrvalue:])
return filevalue
filevalue=[]
svalue=[]
rvalue=[]
shname=[]
fh=open_xls(allxls[0])
sh=getsheet(fh)
x=0
for sheet in sh:
shname.append(sheet.name)
svalue.append([])
x+=1
for shnum in range(0,x):
for fl in allxls:
print("正在读取文件:"+str(fl)+"的第"+str(shnum)+"个标签的…")
filevalue=getfilect(fh,fl,shnum)
svalue[shnum].append(filevalue)
sn=x
fn=len(allxls)
endvalue=[]
def getsvalue(k):
for z in range(k,k+fn):
endvalue.append(svalue[0][0][z])
return endvalue
wb1=xlsxwriter.Workbook(endxls)
ws=wb1.add_worksheet()
polit=0
linenum=0
for s in range(0,sn*fn,fn):
thisvalue=getsvalue(s)
tvalue=thisvalue[polit:]
for a in range(0,len(tvalue)):
for b in range(0,len(tvalue[a])):
for c in range(0,len(tvalue[a][b])):
data=tvalue[a][b][c]
ws.write(linenum,c,data)
linenum+=1
polit=len(thisvalue)
wb1.close()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102