First, install the XLRD module
Download the HTTP://PYPI.PYTHON.ORG/PYPI/XLRD module installation to the Python website, provided the Python environment is already installed.
Second, the use of the introduction
1. Import Module
Import xlrd
2. Open Excel file to read data
data = Xlrd.open_workbook (' Excelfile.xls ')
3, the use of skills
Get a worksheet
Table = data.sheets () [0] #通过索引顺序获取
Table = Data.sheet_by_index (0) #通过索引顺序获取
Table = data.sheet_by_name (U ' Sheet1 ') #通过名称获取
Get the values (arrays) for the entire row and the entire column
Table.row_values (i)
Table.col_values (i)
Get the number of rows and columns
nrows = Table.nrows
Ncols = Table.ncols
Cyclic row and column table data
For I in Range (nrows):
Print Table.row_values (i)
Cell
CELL_A1 = Table.cell (0,0). Value
CELL_C4 = Table.cell (2,3). Value
Using row and column indexes
CELL_A1 = Table.row (0) [0].value
CELL_A2 = Table.col (1) [0].value
A simple write
Row = 0
Col = 0
# type 0 empty,1 string, 2 number, 3 date, 4 Boolean, 5 error
CType = 1 value = ' cell values '
XF = 0 # Extended Formatting
Table.put_cell (Row, col, CType, value, XF)
Table.cell (0,0) #单元格的值 '
Table.cell (0,0). Value #单元格的值 '
Python operation Excel Read--using XLRD