我有一个包含多个分号的字符串。
'firstline: abc \n secondline: bcd \n thirdline: efg'
我想使用Xlsx Writer在Excel单元格中写入以下字符串:
第一行: abc
第二行: bcd
第三行: efg
这是我的做法:
description_combined =
'''
firstline: abc
secondline: bcd
thirdline: efg
'''
spanInserted = []
spanInserted = description_combined.split("\n")
result = ''
for spans in spanInserted:
strr1 = '{}:'.format(spans.split(":")[0])
strr2 = spans.split(":")[1]
result += '''bold , "{}" , "{}" ,'''.format(str(strr1),str(strr2))
result = result[:-1]
# print result
worksheet.write_rich_string('A1', result)
这是我在Excel单元格中得到的结果:
粗体,"第一行:","abc",粗体,"第二行:","bcd",粗体,"第三行:","efg"