如何使用 xlsxwriter 将多个元素写入一个单元格?

How to write multiple elements into one cell using xlsxwriter?

我正在使用 xlsx 编写器

我有一个列表列表,像这样:

lst = [[aaa1,aaa2,aaa3],[bbb1,bbb2,bbb3]]

我想将列表的第一个元素([aaa1,aaa2,aaa3])写入单个单元格,依此类推。这是结果应该是什么样子的图片:

我不知道该怎么做this.Thanks求助<3

您可以指定单元格索引:

import xlsxwriter

workbook = xlsxwriter.Workbook('write_data.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write(0, 0, 1234)     # Writes an int
worksheet.write(1, 0, 1234.56)  # Writes a float
worksheet.write(2, 0, 'Hello')  # Writes a string
worksheet.write(3, 0, None)     # Writes None
worksheet.write(4, 0, True)     # Writes a bool

workbook.close()

在您的情况下,您可以使用 joinadd_format:

import xlsxwriter

workbook = xlsxwriter.Workbook('write_data.xlsx')
worksheet = workbook.add_worksheet()
wrap_format = workbook.add_format({'text_wrap': True})

lst = [['aaa1','aaa2','aaa3'],['bbb1','bbb2','bbb3']]
worksheet.write(0, 0, '\n'.join(lst[0]), wrap_format)
worksheet.write(1, 0, '\n'.join(lst[1]), wrap_format)

workbook.close()

您可以在 xlsxwriter 文档中找到您想要的一切。

workbook   = xlsxwriter.Workbook('filename.xlsx')
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet()
worksheet1.write('A1', 123)
workbook.close()