본문 바로가기
파이썬

파이썬 Openpyxl 인덱스로 워크 시트에서 행을 가져 오는 방법

by º기록 2020. 10. 26.
반응형

Openpyxl 및 python3.5를 사용하여 아래 첨자를 사용하여 Excel 워크 시트에서 첫 번째 행을 가져 오려고했지만 오류가 발생했습니다.

# after getting filename
# after loading worksheet
# to get the first row of the worksheet
first_row = worksheet.rows[0]

# I get 
Traceback (most recent call last):
      File "<pyshell#54>", line 1, in <module>
      first_row = phc_th_sheet.rows[1]
TypeError: 'generator' object is not subscriptable

첫 번째 행을 얻는 것과 관련하여 나는 또한 시도했습니다 first_row = worksheet.(row=1) # and first_row = workstation.rows [: 1]

작동하지 않았습니다. 제안 사항이 있거나 openpyxl에서 사용할 수없는 기능입니까?


 

해결 방법

 

마침내 문서에서 답을 찾았습니다.

first_row = worksheet[1]
# worksheet[row_index_from_1]

이것은 나를 위해 일했습니다.

 

참조 페이지 https://stackoverflow.com/questions/40561670

 

 

반응형

댓글