Python reads data from Excel tables

Source: Internet
Author: User

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:// "title=" Sp170220_170919.png "alt=" Wkiol1iqsk_i_8pyaabapczce2s311.png "/>

Installation Complete

650) this.width=650; "src=" Https:// "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:// "title=" Sp170220_171014.png "alt=" Wkiom1iqsohtywmlaaar01acjvc626.png "/>

3. Writing a Python script

650) this.width=650; "src=" Https:// "title=" Sp170220_171040.png "alt=" Wkiom1iqspecal2kaadlsdeooio556.png "/>


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:// "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:// "title=" Sp170220_171132.png "alt=" Wkiol1iqsszjzztfaaecgevj2fu954.png "/>

Print (Sheet.cell)

Run results

650) this.width=650; "src=" Https:// "title=" Sp170220_171200.png "alt=" Wkiol1iqsuqtmi90aad_vh12pi4112.png "/>

Python reads data from Excel tables

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.