import pandas as pd
import os
from openpyxl import load_workbook
import datetime
import easygui as gui
address = os.getcwd()
def find(name,name2):
for root, dirs, files in os.walk(address):
if name in files and name2 in files:
df1 = pd.read_excel(os.path.join(root,name))
df2 = pd.read_excel(os.path.join(root,name2))
#df1 = df1.drop(df1.columns[[1,2,3,4,5,6]], axis = 1)
df2 = df2.drop(df2.columns[[2,3]], axis = 1)
horizontal_stack = pd.concat([df1, df2], axis = 1)
horizontal_stack.insert(8, '单品编号', 0)
horizontal_stack.insert(9, '单品库存:Ontraio', 0)
horizontal_stack.insert(10, '单品库存:Memphis', 0)
horizontal_stack.insert(11, '单品库存:Kansas City', 0)
horizontal_stack.insert(12, '组合库存:Ontario', 0)
horizontal_stack.insert(13, '组合库存:Memphis', 0)
horizontal_stack.insert(14, '组合库存:Kansas City', 0)
horizontal_stack.insert(15, 'SFP', 0)
horizontal_stack.insert(21, '单品SFP', 0)
#num_inserted_row = 7
#for i in range(num_inserted_row):
#horizontal_stack.insert(8, 'new_col%s' % i, 0)
export_excel = horizontal_stack.to_excel(address + '\\test_Inventory.xlsx', index = None, header = True)
try:
s = gui.enterbox(image = 'PA.png', msg ='enter first excel file name: ', title ='Paramount Automotive')
s2 = gui.enterbox(image = 'PA.png', msg = 'enter second excel file name: ', title = 'Paramount Automotive')
find(s + '.xlsx',s2 + '.xlsx')
except:
None
wb = load_workbook(address + '\\test_Inventory.xlsx')
ws = wb.active
wb2 = load_workbook(address + '\\Not SFP.xlsx')
ws2 = wb2.active
num = 1
while 1:
cell = ws.cell(row=num, column=1).value
if cell:
num = num +1
else:
break
exit()
num2 = 1
for row in range (1, ws2.max_row):
if(ws2.cell(row,1).value is None):
break
else:
num2 = num2 + 1
for h in range (num):
ws['I%d' % (h+1)].value = '=IF(ISERROR(FIND(" : ",H%d)),H%d,RIGHT(H%d,LEN(H%d)-FIND(" : ",H%d)-2))' % (h + 1, h + 1, h + 1, h + 1, h + 1)
ws['I1'].value = '单品编号'
for j in range (num):
ws['J%d' % (j+1)].value = '=VLOOKUP($I%d,$Q:$X, 3,0)' % (j + 1)
ws['J1'].value = '单品库存:Ontraio'
for k in range (num):
ws['K%d' % (k + 1)].value = '=VLOOKUP($I%d,$Q:$X, 4,0)' % (k + 1)
ws['K1'].value = '单品库存:Memphis'
for l in range (num):
ws['L%d' % (l + 1)].value = '=VLOOKUP($I%d,$Q:$X, 5,0)' % (l + 1)
ws['L1'].value = '单品库存:Kansas City'
for m in range(num):
ws['M%d' % (m + 1)].value = '=MINIFS(J:J,$A:$A,$A%d)' % (m + 1)
ws['M1'].value = '组合库存:Ontario'
for n in range(num):
ws['N%d' % (n + 1)].value = '=MINIFS(K:K,$A:$A,$A%d)' % (n + 1)
ws['N1'].value = '组合库存:Memphis'
for o in range(num):
ws['O%d' % (o + 1)].value = '=MINIFS(L:L,$A:$A,$A%d)' % (o + 1)
ws['O1'].value = '组合库存:Kansas City'
for p in range(num):
ws['P%d' % (p + 1)].value = '=IF(AND(M%d>=5,N%d>=5,O%d>=5),"Seller Fulfilled Prime - Complete",IF(AND(M%d>=5,N%d>=5,O%d<5),"Seller Fulfilled Prime - Ontario + Memphis",IF(AND(M%d>=5,N%d<5,O%d>=5),"Seller Fulfilled Prime - Ontario + Kansas City",IF(AND(M%d<5,N%d>=5,O%d>=5),"Seller Fulfilled Prime - Kansas City + Memphis",IF(AND(M%d<5,N%d<5,O%d<5),"Default Amazon Template",IF(AND(M%d>=5,N%d<5,O%d<5),"Seller Fulfilled Prime - Ontario",IF(AND(M%d<5,N%d>=5,O%d<5),"Seller Fulfilled Prime - Memphis",IF(AND(M%d<5,N%d<5,O%d>=5),"Seller Fulfilled Prime - Kansas City",0))))))))' % (p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1,p + 1)
ws['P1'].value = 'SFP'
for v in range(ws.max_row):
ws['v%s' % (v + 1)].value = '=IF(AND(S%d>=5,T%d>=5,U%d>=5),"Seller Fulfilled Prime - Complete",IF(AND(S%d>=5,T%d>=5,U%d<5),"Seller Fulfilled Prime - Ontario + Memphis",IF(AND(S%d>=5,T%d<5,U%d>=5),"Seller Fulfilled Prime - Ontario + Kansas City",IF(AND(S%d<5,T%d>=5,U%d>=5),"Seller Fulfilled Prime - Kansas City + Memphis",IF(AND(S%d<5,T%d<5,U%d<5),"Default Amazon Template",IF(AND(S%d>=5,T%d<5,U%d<5),"Seller Fulfilled Prime - Ontario",IF(AND(S%d<5,T%d>=5,U%d<5),"Seller Fulfilled Prime - Memphis",IF(AND(S%d<5,T%d<5,U%d>=5),"Seller Fulfilled Prime - Kansas City",0))))))))' % (v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1,v + 1)
ws['V1'].value = '单品SFP'
ws3 =wb.create_sheet('Not SFP')
sheet = wb['Not SFP']
for a in range (num2):
sheet['A%d' % (a + 1)].value = ws2['A%d' % (a + 1)].value
for b in range (num2):
sheet['B%d' % (b + 1)].value = ws2['B%d' % (b + 1)].value
for w in range (ws.max_row):
ws['W%d' % (w + 1)].value = "=VLOOKUP(Q%d,'Not SFP'!$A:$B,2,0)" % (w + 1)
savefile = wb.save(address + '\\test_Inventory.xlsx')
gui.msgbox('Done!!')