目前用的openpyxl,从数据库获取8W行的数据通过openpyxl写入excel,要花费接近8分钟,这也太慢了,用kettle的插件秒进,python有什么方法能提升速度么,或者openpyxl能批量插入么,按行效率太低了
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from openpyxl import Workbook as wbook
def xlsx(filename, rows_info, sheet='Result'):
if filename and sheet:
wb = wbook()
_sheet = wb.active
_sheet.title = sheet
row = _sheet.max_row
for line in rows_info:
if isinstance(line, str):
row_list = [line]
elif isinstance(line, dict):
row_list = list(line.values())
else:
try:
row_list = list(line)
except:
row_list = []
for col in range(0, len(row_list)):
col_info = row_list[col]
_sheet.cell(row, col + 1, col_info)
row += 1
wb.save(filename)
else:
return '文件和sheet不能为空'