简体   繁体   English

使用python在csv文件中写入时如何在列中使用文本换行

[英]How to wrap text with in a column while writing in csv file using python

I am trying to export a file as csv. 我正在尝试将文件导出为csv。 I need to wrap text for a particular column while writing in csv file. 在csv文件中写入时,我需要为特定列换行。 I have a too long string. 我的弦太长了。 i need to write it in a csv file using python. 我需要使用python将其写入csv文件。 While trying to write, it doesn't write in a single cell. 尝试写入时,它不会在单个单元格中写入。 some of the lines are written into next rows. 有些行被写入下一行。 I need to write the whole string in a single cell. 我需要将整个字符串写在单个单元格中。 Please help me to do this. 请帮我做到这一点。

CSV is not formatted. CSV未格式化。 If you want to format the text in the cells, you should consider writing a proper Excel or PDF file. 如果要格式化单元格中的文本格式,则应考虑编写适当的Excel或PDF文件。

Anyway it looks like that newline characters (\\n or \\r\\n) can be used in CSV files if using semicolon as separator, so this may not be portable. 无论如何,如果使用分号作为分隔符,看起来可以在CSV文件中使用换行符(\\ n或\\ r \\ n),因此这可能不可移植。

To write an Excel file, you can use libraries like openpyxl or xlwt . 要编写Excel文件,可以使用openpyxlxlwt类的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM