1. Install the third-party module XLRD on the Windows command line, first cut to the Python installation directory (PYTHON34), then cut to scripts, then enter the command Easy_install XLRD Press ENTER to install
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/8D/C7/wKioL1iqsk_i_8pyAABAPczce2s311.png "title=" Sp170220_170919.png "alt=" Wkiol1iqsk_i_8pyaabapczce2s311.png "/>
Installation Complete
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8D/C7/wKioL1iqsmWjiufpAAEhM4Eyl7A280.png "title=" Sp170220_170949.png "alt=" Wkiol1iqsmwjiufpaaehm4eyl7a280.png "/>
2. Create a new Excel table, then save and create the data
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/8D/CA/wKiom1iqsoHTYWMLAAAR01AcJVc626.png "title=" Sp170220_171014.png "alt=" Wkiom1iqsohtywmlaaar01acjvc626.png "/>
3. Writing a Python script
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/8D/CA/wKiom1iqspeCaL2KAADlSDeoOio556.png "title=" Sp170220_171040.png "alt=" Wkiom1iqspecal2kaadlsdeooio556.png "/>
#utf-8
Import Xlrd #导入第三方模块xlrd
Excel = Xlrd.open_workbook (' c:\\ table. xlsx ') #打开目标表格文件 (fill in the path)
Sheet = excel.sheets () [0] #打开表格文件中的第一张表格, index starting from 0
nrows = Sheet.nrows #获取第一张表格的行数赋值给nrows
For I in Range (nrows): #用一个for循环遍历所有的行数
Print (Sheet.row_values (i)) #打印所有遍历到的行数的内容
Print (Sheet.col_values (1)) #打开第一张表格的第二列
4.f5 Run, Run results
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/8D/C7/wKioL1iqsrfThPekAAEIhpNAfSI404.png "title=" Sp170220_171110.png "alt=" Wkiol1iqsrfthpekaaeihpnafsi404.png "/>
5. Get the contents of the specified number of rows and columns in Excel
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/8D/C7/wKioL1iqsszjzztFAAECGevj2FU954.png "title=" Sp170220_171132.png "alt=" Wkiol1iqsszjzztfaaecgevj2fu954.png "/>
Print (Sheet.cell)
Run results
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/8D/C7/wKioL1iqsuqTMi90AAD_VH12Pi4112.png "title=" Sp170220_171200.png "alt=" Wkiol1iqsuqtmi90aad_vh12pi4112.png "/>
Python reads data from Excel tables