Python module - xlrd module reads Excel data

xlrd module

xlrd module description

xlrd is a library for reading data and formatting information from Excel files, whether they are. xls or. xlsx files There are many ways to read xlrd. Open workbook excel file This paper does not deal with complex Excel formulas with formulas and macros

Data description

Install xlrd module

Install with pip

pip install xlrd

Official address'workbook (parameter)

Parameter description Interpretation
filename Path to the spreadsheet file to open
logfile Log files for writing messages and diagnostic information
verbosity Increase the number of trace materials written to the log file
use_mmap Use mmap module or not
file_contents Document content
encoding_override File encoding
formatting_info format information
on_demand=False False: there is no special requirement. All are loaded by default
ragged_rows=False False state is empty row and empty cell

Parameter example

        logfile=<_io.TextIOWrapper name='' mode='w' encoding='UTF-8'>, 

Read Excel object parameters and examples

# -*- coding:utf8 -*-
import xlrd                                         #Import module
Excel_Obj = xlrd.open_workbook('../file/111.xls')   #Open Excel file

print("Excel Participants:",Excel_Obj)
print("Excel All tab names",Excel_Obj.sheet_names())

print("Index get data", Excel_Obj.sheet_by_index(0))
print("Index get data", Excel_Obj.sheets()[0])

Tab_Obj = Excel_Obj.sheet_by_name(u'sheet1')        #Select the specified tab object, and sheet1 is the tab name

print("Number of tab lines:",Tab_Obj.nrows)
print("Tab columns:",Tab_Obj.ncols)
print("Specify line contents:",Tab_Obj.row_values(0))        #Index row 1 data
print("Specify line contents:",Tab_Obj.row_values(0,3))      #Index row 1, starting with column 4 data
print("Specify column contents:",Tab_Obj.col_values(0))        #Index column 1 data
print("Specify column contents:",Tab_Obj.col_values(0,3))      #Index column 1, starting at row 4
print("Index by line number:",Tab_Obj.row(0)[1].value)    #Index row 1, column 2

Tags: Programming Excel pip encoding

Posted on Tue, 03 Dec 2019 08:15:34 -0500 by baw