更新的代码 - 如何使用 xlsxwriter 将所有值放入 Python 的列中

Updated code - How to put all values in a column in Python using xlsxwriter

我还在学习这项技术。我可以知道如何使用 python 和 xlsx writer 将所有值放在一列中吗?

例如

my_dict = {
'Bob': ['eating', 'watching', 'drinking'], 
'Ann': ['shopping', 'eating', 'drawing'], 
'May': ['riding', 'singing', 'dancing']
}

我所做的是将它放在另一个专栏中。

col_num = 0
row_num = 7
        
col_num = 0
row_num = 7
        
for key, value in my_dict.items():
    worksheet.write_column(row_num, col_num, key)
    worksheet.write_column(row_num + 1, col_num + 1, value)
    row_num += 1

请问如何实现这种格式? 希望得到您的意见和建议。谢谢

对键使用 write,对值使用 write_column。

此外,将行号增加值的长度。

col_num = 0
row_num = 7
        
for key, value in my_dict.items():
    worksheet.write(row_num, col_num, key)
    worksheet.write_column(row_num,  col_num + 1, value)
    row_num += len(value)

workbook.close()

我明白了。 这就是我所做的:

row_num = 7
        
for key, value in my_dict.items():
    col_num = 0
    worksheet.write(row_num, col_num, key)
    for i in value:
        col_num = 1
        worksheet.write(row_num, col_num, i)
        row_num += 1