ValueError: row index was 65536, not allowed by .xls format
#因为xlwt不支持大数据插入 所以用openpyxl 支持一百万的数据
下面展示一些 内联代码片
。
输入文件名,sheet名称,Excel的标题list 和内容的list
再次写入数据只能替换原Excel的内容
def WriteInExcel2(dest_filename,ws1sheetname,ws1title,ws1content):
wb = Workbook()
dest_filename = dest_filename
ws1 = wb.active
ws1.title = ws1sheetname
ws1['A4'] = '010174' # 写单元格
ws1.cell(row=65536, column=1).value = '01017465536'
ws1.cell(row=995536, column=1, value='995536test')
ws1.column_dimensions['A'].width = 20.0 #设置列的列宽
# ws1.column_dimensions['B'].width = 20.0
# 写入标题
for col in range(len(ws1title)):
ws1.cell(row=1, column=col + 1).value = ws1title[col]
pass
for i in range(len(ws1content)):
for j in range(len(ws1content[i])):
ws1.cell(row=i + 2, column=j + 1).value = ws1content[i][j]
#print(ws1.column_dimensions)
wb.save(filename=dest_filename)