인프런 - 강의/김대리님 이게 바로 업무자동화입니다

6 - 회사에 필요한 데이터만 뽑아내서 엑셀에 넣기 - 2

----___<<<<< 2020. 3. 30. 16:51

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)


read_wb_result = load_workbook("./result.xlsx")

read_ws_result = read_wb_result["Sheet1"]



for i in list3 :

    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(temp_list)

    start_num = 12

    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

        start_num = start_num +1



    read_wb_result.save("excel/" + company + ".xlsx")