The xlrd Python module to read xls file with error

installation

pip3 install xlrd

usage

Sheet numbering begins with 0
rows, colnum numbering starts from 0
merged cells return only the first cell contents
Sheets can only be called once, you can get all the sheet take idx
regardless of the type of data within a table is int or str, pure digital content will returns a float

Examples

import xlrd
file = "name_list.xls"
data = xlrd.open_workbook(file)
table = data.sheets()#Read all sheet by idx

table_1 = table[1] #Input signal sheet
name = table_in.col_values(2, start_rowx=1, end_rowx=None) #Get col.C w/o header
print(name) #output ['Ada','Barry','Colin','Darwin']

table_2 = table[2] #Next sheet
...

note

py file name can not be named xlrd otherwise it will error and import conflictAttributeError: module 'xlrd' has no attribute 'open_workbook'

Guess you like

Origin www.cnblogs.com/azureology/p/12344428.html