Вывод из Python в *.xls

 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
def MakeXls(self,event):
self.t1=self.tc1.GetValue()
self.t2=self.tc2.GetValue()
term=self.tc3.GetValue()
res=self.db.TakeForReport(self.t1,self.t2,term)
if term:
terms=term.split(',')
terms=self.db.takeTerminals()
else:
terms=self.db.takeTerminals()
wb=Workbook()
ws=wb.add_sheet('Report')
count=1
for term in terms:
amount=amountAll=amountAllBlag=donate=0
for i in res:
if term[0]==i[0]:
if i[4]<>889:
amount += i[1]
amountAll += i[2]
if i[3].rfind("donate_prc=")>0:
donate += ((100*i[2]/(100-int(i[3][i[3].rfind("donate_prc=")+11:i[3].find('&field10')])))-i[2])
elif i[3].rfind("cepient=887")>0:
donate += float(i[3][i[3].rfind("&d=")+3:i[3].rfind('&kgses=')].replace(',','.'))
elif i[3].rfind("cepient=110")>0:
donate += float(i[3][i[3].rfind("&d=")+3:].replace(',','.'))
else:
amountAllBlag += i[2]
if amountAll or amountAllBlag:
count += 1
ws.write(count,1,term[0])
ws.write(count,2,round(amountAll,2))
ws.write(count,3,round(amountAll-amount,2))
ws.write(count,4,round(amountAllBlag,2))
ws.write(count,5,round(donate,2))
wb.save('xls\\Rep_'+str(datetime.datetime.now())[0:19].replace(' ','_').replace(':','-')+'.xls')
self.Close()