How to write a list to xlsx using openpyxl

后端 未结 3 520
失恋的感觉
失恋的感觉 2020-12-06 03:10

I have a list of some values in Python and want to write them into an Excel-Spreadsheet using openpyxl.

So far I tried, where lstStat is a list of integers that need

3条回答
  •  佛祖请我去吃肉
    2020-12-06 03:48

    Openpyxl does not allow you to write lists in excel cells, however if you convert the list into a string you can paste it into excel.

    e.g. This would cause an error

    my_list = ['1','2','3'] ws.cell(row=r, column=1).value = my_list

    However this would paste the string of the list into excel

    my_list = ['1','2','3'] new_list = str(my_list) ws.cell(row=r, column=1).value = new_list

提交回复
热议问题