Obtain data in excel using python

Source: Internet
Author: User

To process excel in python, you must use a third-party module xlrd. Therefore, for windows, run the following command in cmd: E: \ ANZHUANG \ Python \ Scripts> easy_install xlrd (the path must be in python scripts and easy_install must be installed)

# Coding = utf-8import xlrddef print_xls (path): data = xlrd. open_workbook (path) # Open exceltable = data. sheets () [1] # Open the sheet nrows = table in excel. nrows # Number of valid data rows captured books = [] for I in range (nrows): ss = table. row_values (I) # Get all values of a row. The values in each column exist as list items # print ssfor I in range (len (ss )): print ss [I] # output the values of each column in a row: print '++' if _ name __ = '_ main __': print_xls ('d :\\ document \ 431547909921.xls ')

The content format in excel is as follows:

197 10208014 HUANG Zhao Male School of Medicine Preventive medicine Jingjin University Economics
198 10208006 Song Ma Xiaowei Female School of Medicine Preventive medicine School of Medicine Clinical Medicine
199 10207014 Yang Yuanyuan Female School of Medicine Pharmaceutical engineering School of Medicine Stomatology
200 10207018 Zulpiya Female School of Medicine Pharmaceutical engineering School of Medicine Clinical Medicine
201 10207029 Weekly Stress Wave Male School of Medicine Pharmaceutical engineering School of Medicine Clinical Medicine

Output result:

199.0
10207014.0
Yang Yuanyuan
Female
School of Medicine
Pharmaceutical engineering
School of Medicine
Stomatology
++
200.0
10207018
Zulpiya
Female
School of Medicine
Pharmaceutical engineering
School of Medicine
Clinical Medicine
++
201.0
10207029
Weekly Stress Wave
Male
School of Medicine
Pharmaceutical engineering
School of Medicine
Clinical Medicine
++

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: info-contact@alibabacloud.com 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.