2017-03-22 1 views
0

그래서 다른 코드를 입력하여 코드를 특정 열에 인쇄하려고합니다. 그래서 사람이 5 가지 다른 유형의 영화를 입력하고 엑셀 파일을 통해 openpyxl을 반복하고 5 개의 영화를 찾고 전체 줄을 인쇄하도록 코드를 만들었지 만 오류는 계속해서 튀어 나오지 않습니다. 이 내 코드입니다Openpyxl : AttributeError : '통합 문서'개체에 '셀'속성이 없습니다.

Traceback (most recent call last): 
File "C:/Users/Shay/PycharmProjects/untitled/Assignment ITN.py", line 39, in <module> 
    listcreator(movieID) 
File "C:/Users/Shay/PycharmProjects/untitled/Assignment ITN.py", line 28, in listcreator 
    if sheet.cell(row=r, column=c).value == movieOne: 
AttributeError: 'Workbook' object has no attribute 'cell' 

: 나는 또한 내가 멍청한 놈 코더입니다 그래서 미안 해요 언급해야

import csv 
import openpyxl 
from openpyxl import load_workbook 

movieID = openpyxl.load_workbook(filename="C:/Users/Shay/Downloads/Movie IDs - Student Copy.xlsx") 
movie_ID = movieID.active 


movie_ID_List = [] 
movie_Ratings_list = [] 
mveavg = [] 

movieOne = input("Type first Movie\n") 
movieTwo = input("Type in second movie\n") 
movieThree = input("Type in third movie\n") 
movieFour = input("Type in fourth movie\n") 
movieFive = input("Type in fifth movie\n") 

movieOneList = [] 
movieTwoList = [] 
movieThreeList = [] 
movieFourList = [] 
movieFiveList = [] 

def listcreator(sheet): 
    for r in range(1, 27278): 
     for c in range(1,2): 
      if sheet.cell(row=r, column=c).value == movieOne: 
       movieOneList.append(sheet.cell(row=r, column=0)) 
      if sheet.cell(row=r, column=c).value == movieTwo: 
       movieTwoList.append(sheet.cell(row=r, column=0)) 
      if sheet.cell(row=r, column=c).value == movieThree: 
       movieThreeList.append(sheet.cell(row=r, column=0)) 
      if sheet.cell(row=r, column=c).value == movieFour: 
       movieFourList.append(sheet.cell(row=r, column=0)) 
      if sheet.cell(row=r, column=c).value == movieFive: 
       movieFiveList.append(sheet.cell(row=r, column=0)) 

listcreator(movieID) 

print(movieOneList) 
print(movieTwoList) 
print(movieThreeList) 
print(movieFourList) 
print(movieFiveList) 
movieOneList - (movieOneList[0]) 
movieTwoList - (movieTwoList[0]) 
movieThreeList - (movieThreeList[0]) 
movieFourList - (movieFourList[0]) 
movieFiveList - (movieFiveList[0]) 
print(movieOneList) 
print(movieTwoList) 
print(movieThreeList) 
print(movieFourList) 
print(movieFiveList) 

이 질문은 정말 보이는 경우가

출력이

해결하는 방법을 알고 기본이지만 도움을 좋아할 것입니다

답변

1

변수를 더 잘 나타내야합니다.

listcreator 함수는 Worksheet 객체를 사용합니다. 그러나 호출 할 때 해당 북의 활성 시트 인 movie_ID 대신 상단에로드하는 통합 문서 개체 인 movieID을 전달합니다.

이러한 개체를 좀 더 적절하게 호출하면 잘못 수행 한 것을 더 쉽게 볼 수 있습니다.

관련 문제