Python xlrd, a common method for reading excel, pythonxlrd
I watched a video on excel operations by the old K. I am very grateful to the old K for sharing it!
To install the xlrd module, open cmd and enter the command: pip install xlrd to install it. If it has been installed, it is shown as follows:
You can use the following methods to read excel files from xlrd:
''' 1. open the file ''' xl = xlrd. open_workbook (file) ''' 2. Obtain sheet ''' print (xl. sheet_names () # obtain the sheet name print (xl. sheets () # obtain the sheet object print (xl. nsheets) # obtain the total number of sheets print (xl. sheet_by_name (u "directory") print (xl. sheet_by_index (1) ''' 3. Obtain the summary data in the sheet ''' table1 = xl. sheet_by_name (u "directory") print (table1.name) print (table1.ncols) print (table1.nrows) ''' 4. Batch read by cells ''' print (table1.row _ values (0 )) # obtain the value of row n if the display value of the first row of the merged cell is null print (table1.row (0) # obtain the value and Type print (table1.row _ types (0 )) print (table1.col _ values (, 4) # Get the column, slice print (table1.row _ slice (, 2 )) ''' 5. Read specific cells ''' # value: print (table1.cell ). value) print (table1.cell _ value (1, 2) print (table1.row (1) [2]). valueprint (table1.col (2) [1]). value # print (table1.cell ). ctype) print (table1.cell _ type (1, 2) print (table1.row (1) [2]. ctype) ''' 6. Common techniques (0, 0) to convert to A_1 ''' print (xlrd. cellname (0, 0) print (xlrd. cellnameabs (0, 0) print (xlrd. colname (0 ))