Skip to content

파이썬 라이브러리 xlrd #

Find similar titles

8회 업데이트 됨.

Edit

Structured data

Category
Programming

엑셀파일을 읽을 수 있게 해주는 파이썬 라이브러리, xlrd #

xlrd는 MicroSoft Office의 Excel 형식의 파일을 읽을 수 있게 해주는 파이썬 라이브러리이다. 각 시트별로 내용을 읽을 수 있으며 엑셀에서 설정한 셀 타입대로 값을 읽을 수 있다.

설치방법 #

pip를 이용하여 설치 할 수 있다.

pip install xlrd

사용법 #

기본사용법 #

from xlrd import open_workbook
wb = open_workbook('FilePath')
for sheet in wb.sheets():
    print sheet.name
    for i in range(sheet.nrows):
        row = sheet.row(i)
        for c in row:
            print c.value

파일 읽기 #

xlrd 모듈의 open_workbook 함수를 통해 엑셀 파일을 읽는다.

wb = open_workbook('FilePath')

시트 다루기 #

모든 시트 가져오기

sheets = wb.sheets()

시트 이름 얻기

names = wb.sheet_names()

이름으로 시트 가져오기

sheet = wb.sheet_by_name('SheetName')

시트 내용 다루기 #

row 수 얻기

n = sheet.nrows

특정 라인 row 가져오기(각 cell값의 리스트)

row = sheet.rows(i)
values = sheet.row_values(i)

Suggested Pages #

0.0.1_20231010_1_v71