python openpyxl笔记

import warnings

warnings.filterwarnings("ignore") # 如果没有此行代码,则会出现警告提示: UserWarning: Discarded range with reserved name warnings.warn("Discarded range with reserved name")原因是会忽略掉excel中的其他一些设置,对excel中我们正常取值是没有影响的,可以忽略

wb = openpyxl.load_workbook(file_name, read_only=True) #打开文件

wb.get_sheet_names() #获取所有的sheet_name

ws = wb.get_sheet_by_name(sheet_name) #获取sheet对象

title = ws.title #sheet名
rows = ws.get_highest_row() #行数
cols = ws.get_highest_column()#列数

ws.cell(row=1, column=3).value #获取cell的值,如果cell值为空,ws.cell(row=1, column=3)为None

posted @ 2016-04-07 12:09  forwhy  阅读(1720)  评论(0编辑  收藏  举报