편집 기록

편집 기록
  • 프로필 엽토군님의 편집
    날짜2019.02.19

    python excel 사용법 에서 sheet는 사용법이 궁금합니다


    import openpyxl
    
    
    list = ['X', '알파', '베타', '감마', 'B/A', 'C/A', 'C/B']
    initSet = ['0.1', '0.2', '0.3', '0.4','0.5','0.6','0.7','0.8','0.9']
    
    A = [0.3, 0.5, 0.7, 0.4, 0.2, 0.6, 0.4, 0.8, 0.2]
    B = [0.1, 0.3, 0.5, 0.7, 0.9, 0.5, 0.3, 0.2, 0.1]
    C = [0.1, 0.4, 0.2, 0.1, 0.5, 0.3, 0.2, 0.1, 0.5]
    
    
    def Part1():
        wb = openpyxl.Workbook('part1.xlsx')
    
        for i in range(0,9):
            sheets = wb.create_sheet('sheet%d' % (i), i)
    
        wb.save('sam.xlsx')
    
    
    def sam():
        wlb = openpyxl.load_workbook('sam.xlsx')
        sheet = wlb.active
    
        for i in range(1,len(list)):
            sheet['A%d'%(i+1)] = list[i]
            cell = sheet['A%d'%(i+1)]
    
        for i in range(0,len(initSet)):
    
            sheet[str(chr(i+66))+'1'] = initSet[i]
            cell = sheet[str(chr(i+66))+'1']
    
            sheet[str(chr(i+66))+'2'] =  A[i]
            cell =  sheet[str(chr(i+66))+'2']
    
            sheet[str(chr(i+66))+'3'] =  B[i]
            cell =  sheet[str(chr(i+66))+'3']
    
            sheet[str(chr(i+66))+'4'] =  C[i]
            cell =  sheet[str(chr(i+66))+'3']
    
    
        wlb.save('KMU.xlsx')
    
    
    Part1()
    sam()
    
    

    이게 제 코드이고 여기서 sheet를 1~9 까지 위 데이터를 넣고 싶은데

    코드를 돌리면 sheet1에만 데이터 값이 들어 가더라고여

    sheet를 여러개 사용 하는 법을 알수 있을까요?

    sheet = wlb.active 부분을 변경 하면 될것 같은데 어떻게 해야 하나요?

  • 프로필 이성현님의 편집
    날짜2019.02.19

    python excel 사용법 에서 sheet는 사용법이 궁금합니다


    import openpyxl
    
    
    list = ['X', '알파', '베타', '감마', 'B/A', 'C/A', 'C/B']
    initSet = ['0.1', '0.2', '0.3', '0.4','0.5','0.6','0.7','0.8','0.9']
    
    A = [0.3, 0.5, 0.7, 0.4, 0.2, 0.6, 0.4, 0.8, 0.2]
    B = [0.1, 0.3, 0.5, 0.7, 0.9, 0.5, 0.3, 0.2, 0.1]
    C = [0.1, 0.4, 0.2, 0.1, 0.5, 0.3, 0.2, 0.1, 0.5]
    
    
    def Part1():
        wb = openpyxl.Workbook('part1.xlsx')
    
        for i in range(0,9):
            sheets = wb.create_sheet('sheet%d' % (i), i)
    
        wb.save('sam.xlsx')
    
    
    def sam():
        wlb = openpyxl.load_workbook('sam.xlsx')
        sheet = wlb.active
    
        for i in range(1,len(list)):
            sheet['A%d'%(i+1)] = list[i]
            cell = sheet['A%d'%(i+1)]
    
        for i in range(0,len(initSet)):
    
            sheet[str(chr(i+66))+'1'] = initSet[i]
            cell = sheet[str(chr(i+66))+'1']
    
            sheet[str(chr(i+66))+'2'] =  A[i]
            cell =  sheet[str(chr(i+66))+'2']
    
            sheet[str(chr(i+66))+'3'] =  B[i]
            cell =  sheet[str(chr(i+66))+'3']
    
            sheet[str(chr(i+66))+'4'] =  C[i]
            cell =  sheet[str(chr(i+66))+'3']
    
    
        wlb.save('KMU.xlsx')
    
    
    Part1()
    sam()
    
    

    이게 제 코드이고 여기서 sheet를 1~9 까지 위 데이터를 넣고 싶은데

    코드를 돌리면 sheet1에만 데이터 값이 들어 가더라고여

    sheet를 여러개 사용 하는 법을 알수 있을까요?

    sheet = wlb.active 부분을 변경 하면 될것 같은데 어떡해 해야 하나요??