import xlsxwriter
# 写excel
def write_excel(all):
workbook = xlsxwriter.Workbook('test.xlsx') # 表名
worksheet = workbook.add_worksheet(u'sheet1')
# 表头 也可使用worksheet.write('0', '0', 'A') worksheet.write('0', '1', 'B')的方式
worksheet.write('A1', 'A')
worksheet.write('B1', 'B')
worksheet.write('C1', 'C')
worksheet.write('D1', 'D')
# 二维数组多行写入
for x, one in enumerate(all):
for y, i in enumerate(one):
# 第一行为表头,x需+1
worksheet.write(x+1, y, i)
workbook.close()
if __name__ == '__main__':
all = []
for i in range(1,5):
one = []
for j in range(6,10):
one.append(i*j)
all.append(one)
write_excel(all)
python 生成Excel表,多行数据写入
最新推荐文章于 2024-09-03 21:53:59 发布