Python工作表.write将2列连接成1列



我有两列:

  • 日期
  • 用户

我试图将两列连接起来,最后只得到一列,如下所示:

  • 日期/用户

但我不确定在使用Python工作表时如何做到这一点。编写

这里有人有这个班的经验吗?

当然,对于已经使用此类的用户来说,这应该是一个简单的解决方案

import xlsxwriter
worksheet.write('A' + str(x), unicode(Date , 'utf-8'), headerBorderFormat)
worksheet.write('B' + str(x), unicode(Username, 'utf-8'), headerBorderFormat)
worksheet.write('C' + str(x), unicode(Date + ' / ' + Username, 'utf-8'), headerBorderFormat)
# get and display one row at a time.
for row in details:
x += 1
worksheet.write('A' + str(x), row[0], dateFormat)
worksheet.write('B' + str(x), row[1], tableDataFormat)
#here I have to concat row[0] + ' / ' + row[1]

workbook.close()

如果row的第一个元素是datetime对象,第二个元素是字符串,当您提供所需的日期格式时(请参阅https://strftime.org/):

# single column header:
col_name = unicode(Date , 'utf-8') + ' / ' + unicode(Username, 'utf-8')
worksheet.write('A' + str(x), col_name, headerBorderFormat)
# get and display one row at a time.
for row in details:
x += 1
format = '%Y%m%d'
cell_content = row[0].strftime(format) + ' / ' + row[1]
worksheet.write('A' + str(x), cell_content, tableDataFormat)

最新更新