from openpyxl import load_workbook
read_wb = load_workbook('./test.xlsx', data_only=True)
read_ws = read_wb["Sheet1"]
list1 = []
row = 70
for i in range(2, row) :
list1.append(read_ws.cell(i, 2).value)
print(list1)
list2 = set(list1)
print(list2)
list3 = list(filter(None, list2))
print(list3)
for i in list3 :
read_wb_result = load_workbook("./result.xlsx")
read_ws_result = read_wb_result["Sheet1"]
current_company = i
temp_list = []
for j in range(2, row) :
# j = 2,3,4,5,6,7 --
if current_company == read_ws.cell(j, 2).value :
temp_list.append(j)
company = read_ws.cell(temp_list[0], 2).value
owner = read_ws.cell(temp_list[0], 3).value
user = read_ws.cell(temp_list[0], 4).value
read_ws_result["B1"] = company
read_ws_result["B2"] = owner
read_ws_result["B3"] = user
print(current_company)
print(temp_list)
start_num = 12
final_price = 0
for oneOfTemp in temp_list :
print(read_ws.cell(oneOfTemp, 1).value)
read_ws_result["A" + str(start_num)] = read_ws.cell(oneOfTemp, 1).value
read_ws_result["B" + str(start_num)] = read_ws.cell(oneOfTemp, 2).value
read_ws_result["C" + str(start_num)] = read_ws.cell(oneOfTemp, 4).value
read_ws_result["D" + str(start_num)] = read_ws.cell(oneOfTemp, 7).value
read_ws_result["E" + str(start_num)] = read_ws.cell(oneOfTemp, 8).value
# read_ws.cell(oneOfTemp, 5).value = 공급가
# read_ws.cell(oneOfTemp, 5).value
# read_ws.cell(oneOfTemp, 6).value = 부가세
# 1 - read_ws.cell(oneOfTemp, 7).value = 할인
# read_ws.cell(oneOfTemp, 8).value = 특별할인
read_ws_result["F" + str(start_num)] = (read_ws.cell(oneOfTemp, 5).value +
read_ws.cell(oneOfTemp, 6).value) * \
(1 - read_ws.cell(oneOfTemp, 7).value) - \
read_ws.cell(oneOfTemp, 8).value
temp_price = (read_ws.cell(oneOfTemp, 5).value +read_ws.cell(oneOfTemp, 6).value) * (1 - read_ws.cell(oneOfTemp, 7).value) - read_ws.cell(oneOfTemp, 8).value
if (read_ws.cell(oneOfTemp, 9).value == "Y") :
temp_price = temp_price * 0.5
read_ws_result["G" + str(start_num)] = temp_price
start_num = start_num +1
final_price = final_price + temp_price
read_ws_result["B4"] = final_price
read_wb_result.save("excel/" + company + ".xlsx")
read_wb_result.close()
'인프런 - 강의 > 김대리님 이게 바로 업무자동화입니다' 카테고리의 다른 글
9 - 메일 주소 읽어오기 (Sheet2) (0) | 2020.04.07 |
---|---|
8 - 텍스트 파일로 저장 (0) | 2020.04.07 |
6 - 회사에 필요한 데이터만 뽑아내서 엑셀에 넣기 - 2 (0) | 2020.03.30 |
5 - 회사에 필요한 데이터만 뽑아내서 엑셀에 넣기 (0) | 2020.03.30 |
4 - 회사별로 행 끊어내기 (0) | 2020.03.30 |