格式化写入exl

2022-06-27  本文已影响0人  Tsukinousag
def writeData(news):
    workbook = xlwt.Workbook(encoding = 'utf-8')
    print(workbook)
    worksheet = workbook.add_sheet('MySheet')

    worksheet.write(0, 0, "标题")
    worksheet.write(0, 1, "时间")
    worksheet.write(0, 2, "媒体")
    worksheet.write(0, 3, "网址")

    for i in range(len(news)):
        #print(news[i])
        worksheet.write(i+1, 0, news[i]["origin_title"])
        worksheet.write(i+1, 1, news[i]["datetime"])
        worksheet.write(i+1, 2, news[i]["media"])
        worksheet.write(i+1, 3, news[i]["url"])

    workbook.save('data.xls')
上一篇下一篇

猜你喜欢

热点阅读