-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbillfill.py
71 lines (59 loc) · 2.21 KB
/
billfill.py
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
#用于读取对账单账单金额并填入开票登记表中
import xlwings as xw
import os
import re
billpath=r'E:\新网工作\支付工作\支付收费对账单\2019年2月对账单\存管2月对账单'
fillpath=r'E:\新网工作\支付工作\支付收费对账单\2019年2月对账单\2019年2月存管开票信息'
cellname_bill='G13:G18'
cellname_fill='C17'
sheet_bill='1'
sheet_fill='1.开具增值税发票登记表'
def getbill(billpath,cellname_bill,sheetname):
os.chdir(billpath)
billfiles=os.listdir('.')
global billdict
billdict={}
splitletter='2月'
#获取账单金额数据
for file in billfiles:
exlapp=xw.App(visible=False,add_book=False)
exlapp.display_alerts=False
exlapp.screen_updating=False
wb=exlapp.books.open(file)
billlist=wb.sheets[sheetname].range(cellname_bill).value
print("处理文件"+file+'\n')
if '\\' in billlist:
print(file+' 处理成功'+'\n')
billindex=billlist.index('\\')
billamount=round(billlist[billindex-1],2)
else:
print(file+' 未找到金额\n')
billamount=0
ma=re.split(splitletter,file)
billdict[ma[0]]=billamount
print(file+' 账单金额'+str(billamount))
wb.save()
wb.close()
exlapp.quit()
return billdict
getbill(billpath,cellname_bill,sheet_bill)
def fillbill(fillpath,cellname_fill,sheetname):
os.chdir(fillpath)
fillfile=os.listdir('.')
splitletter='开'
for file in fillfile:
exlapp=xw.App(visible=False,add_book=False)
exlapp.display_alerts=False
exlapp.screen_updating=False
wb=exlapp.books.open(file)
ma=re.split(splitletter,file)
if billdict.get(ma[0]):
wb.sheets[sheetname].range(cellname_fill).value=str(billdict[ma[0]])+'元'
print(file+"修改完毕")
else:
wb.sheets[sheetname].range(cellname_fill).value='无'
print(file+"未找到对应对账单")
wb.save()
wb.close()
exlapp.quit()
fillbill(fillpath,cellname_fill,sheet_fill)