xlrd 주요 내용

project/python 2007. 8. 25. 17:06
Book Class

nsheets: worksheet의 갯수

sheet_by_index(sheetx)

       sheetx: sheet1의 경우에는 0, sheet2의 경우는 1. 이런 식으로 사용
       Returns: 특정 sheet를 선택

sheet_by_name(sheet_name)
       sheet_name: "시트네임" 이런 식으로 사용
       Returns: 특정 sheet를 선택

sheet_names()
       Returns: 시트의 이름들

Sheet Class

Sheet: sheet속의 모든 데이타. 그러나 이 클래스를 직접 불러서 쓸 일은 없고, xlrd.open_workbook("myfile.xls")와 같이 workbook을 읽어와서 sheet_by_index나 sheet_by_name으로 선택한다

Cell(ctype, value): type과 value로 이루어져 있고, 직접 이 클래스를 불러서 쓰진 않는다

cell_type(rowx, colx): cell_type(3, 4) 이런 식으로 쓰며, 셀에 있는 데이타의 type을 반환

cell_value(rowx, colx): cell_type(3, 4) 이런 식으로 쓰며, 셀에 있는 데이타의 value를 반환

col(colx): 예를 들어 보면, 한 칼럼에 있는 전체 내용을 반환한다.

[text:u'Symbol', text:u'A057330', text:u'A038500', text:u'A004870', text:u'A032580', text:u'A047600', text:u'A036420', text:u'A053070', text:u'A017170', text:u'A051530', text:u'A032820', text:u'A053170', text:u'A058550', text:u'A041940' 이런 식으로

row(rowx): 예를 들어 보면, 한 행에 있는 전체 내용을 반환한다.

col_slice(colx, start_rowx=0, end_rowx=None): start_rowx와 end_rowx를 직접 써 넣어서 특정칼럼의 특정부분만 잘라낸다(slice). end_rowx에서 숫자를 안 쓰고 None으로 해도 작동한다. 이 경우에는 내용이 있는 cell까지 계속해서 데이타를 읽어 들인다
row_slice(rowx, start_colx=0, end_colx=None): 위와 같고 행이라는 것만 차이점

name: sheet의 이름

ncols: number of cols(빈 칸이 아닌 내용이 있는 칼럼)
nrows: number of rows(빈 칸이 아닌 내용이 있는 행)

row_types(rowx): 특정 row의 type(cell type과 같은 형태)
row_values(rowx): 특정 row의 값

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

row_slice(rowx, start_colx=0, end_colx=None)를 이용하면 종목코드를 원하는 부분만 읽어올 수 있다
Posted by trigger
,