xlwt针对Ecxec2007之前的版本,即.xls文件,其要求单个sheet不超过65535行,而openpyxl则主要针对Excel2007之后的版本(.xlsx),它对文件大小没有限制。
#-*- coding:utf-8 -*- import openpyxl #设置路径 path = u'F:\postgraduate\test.xlsx' #打开文件 data = openpyxl.load_workbook(path) sheet_name = data[u'用户点播信息'] #获得总行数 n_of_rows = sheet_name.max_row print n_of_rows #读数据 print(sheet_name.cell(row = 13 ,column = 3).value) #写数据 sheet_name['H1'] = u"数据" data.save(path)