xlsxwriter写入
import xlsxwriter
def to_excel(lst1,lst2):
"""write into Excel."""
workbook = xlsxwriter.Workbook(txt.name+"_translated.xlsx")
worksheet = workbook.add_worksheet()
row=col=0
for x,y in zip(lst1,lst2):
worksheet.write(row,col,x)
worksheet.write(row,col+1,y)
row+=1
workbook.close()
Openpyxl 追加写入
import openpyxl
def write_excel(lst):
wb=openpyxl.Workbook()
sht=wb.active
for row in lst:
sht.append(row)
wb.save("1.xlsx")
xlwt 写入一列
import xlwt
def write_excel(lst):
# 创建工作簿
wb= xlwt.Workbook()
# 创建新的工作表sheet2
sht=wb.add_sheet("sheet1")
for i in range(1,len(lst)):
sht.write(i,1,lst[i])
i+=1