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
++