Python worksheet.write 将 2 列连接成 1 列
Python worksheet.write concatenate 2 columns into 1
我有 2 列:
- 日期
- 用户
我试图连接两列,最后只得到一列,如下所示:
- 日期/用户
但我不确定在使用 Python worksheet.write
时该怎么做
这里有人对此有经验吗class?
当然,对于已经使用此 class
的用户来说,这应该是一个简单的解决方案
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
的第一个元素是日期时间对象,第二个元素是字符串,当您提供所需的日期格式时(请参阅 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)
我有 2 列:
- 日期
- 用户
我试图连接两列,最后只得到一列,如下所示:
- 日期/用户
但我不确定在使用 Python worksheet.write
时该怎么做这里有人对此有经验吗class?
当然,对于已经使用此 class
的用户来说,这应该是一个简单的解决方案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
的第一个元素是日期时间对象,第二个元素是字符串,当您提供所需的日期格式时(请参阅 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)