写入xlsx文件 – 换行会导致问题

我正在尝试使用openpyxl模块将一些文本写入xlsx文件。 直到我尝试写文本( text = '\n'.join(list_of_sentences) ),它才text = '\n'.join(list_of_sentences)

它似乎写入正确(没有错误提出),但是当我尝试打开文件,openoffice冻结。 该文件以某种方式损坏。

我已经尝试过text = r'\n'.join(list_of_sentences)但是没有帮助。

也许是因为这个警告:

 C:\Python27\lib\site-packages\openpyxl\styles\styleable.py:111: UserWarning: Use formatting objects such as font directly warn("Use formatting objects such as font directly") 

你能给我一个build议如何正确地做到这一点?

编辑 – 代码:

 with open(file) as f: for line in f: i+=1 splitted = line.strip('\n').split('::') name = splitted[0] text = splitted[1].split('***') text_xlsx = '\n'.join(text) # text_xlsx.replace('_x000D_','\n') worksheet.cell('B{}'.format(i)).style.alignment.wrap_text = True worksheet.cell('B{}'.format(i)).value = text_xlsx 

text_xlsx的示例:

 'dir\\dir\\dir\\dir\\dir\\.file_name.pl-pl::\xef\xbb\xbf<p><strong class="title">&euro;this</strong></p>***<p><span class="text">Please add Peter\'s account &euro;1!.<br /> <a target="_blank" href="some url">click to redirect</a></span></p>\n'