I. Description of the XLRD
XLRD is a module that is designed to read Excel documents in Python and needs to be installed before use.
You can download the tar.gz file to this https://pypi.python.org/pypi/xlrd, then unzip the installation, switch to the extracted folder in the cmd command window, and use
Python setup.py Install
For installation.
Method Two,
Using PIP for installation
Pip Install Xlrd
Second, the use of the introduction
1 Importing Modules
Import xlrd
2 Open an Excel file
data = Xlrd.open_workbook (' Excelfile.xls ')
3 Get a worksheet method
Table = data.sheets () [0] #通过索引顺序获取
table = data.sheet_by_index (0) #通过索引顺序获取
Table = data.sheet_by_name (U ' Sheet1 ') #通过名称获取 4 Gets the value of the entire row or column,--> returns the array table.row_values (i) table.col_values (i) 5 gets the number of rows and columns N rows = Table.nrowsncols = Table.ncols6 Loop table gets row data,---> Return data For i in range (nrows):Print Table.row_values (i) 7 cellcell_a1 = Table.cell (0,0). Value CELL_C4 = Table.cell (2,3). Value can also be indexed with a row number cell_a1 = Table.row (0) [0].value cell_a2 = Table.col (1) [0].value 8 sheet some Property name Gets the name of the sheet at this time, print Table.name
Python read Excel file