首先,需要安装openpyxl库
http://openpyxl.readthedocs.org/en/default/
pyton 2.x
pip install openpyxl
python 3.x
easyinstall openpyxl
准备测试excel文件
firstExcel.py
import openpyxlwb = openpyxl.load_workbook('example.xlsx')print(wb.get_sheet_names())sheet = wb.get_sheet_by_name('Sheet3')print(sheet.title)sheet = wb.get_sheet_by_name('Sheet1')print(sheet['A1'].value)c = sheet['B1']print(c.value)print('Row ' + str(c.row) + ', Column ' + c.column + ' is ' + c.value)print('Cell ' + c.coordinate + ' is ' + c.value)print(sheet['C1'].value)
运行结果:
['Sheet1', 'Sheet2', 'Sheet3']
Sheet32015-04-05 13:34:02ApplesRow 1, Column B is ApplesCell B1 is Apples73