{"id":785,"date":"2013-07-01T00:00:00","date_gmt":"2013-07-01T00:00:00","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2013\/07\/01\/how-do-i-create-a-multiline-cell-csv-file-within-python\/"},"modified":"2023-01-06T16:41:42","modified_gmt":"2023-01-06T16:41:42","slug":"how-do-i-create-a-multiline-cell-csv-file-within-python","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/Programming\/Python\/how-do-i-create-a-multiline-cell-csv-file-within-python.html","title":{"rendered":"Create a Multiline Cell Based CSV File Within Python"},"content":{"rendered":"
Within this short tutorial we will show you the steps required to create a csv file that includes multi-line cells within Python.<\/p>\n
In order to create a mutliline cell within Excel (2010\/2013) the following is required:<\/p>\n
One of the great things with the Python csv module is it takes care of the quotes for you. Below provides an example,<\/p>\n
#!\/usr\/bin\/env python2.7<\/pre>\nimport csv<\/p>\n
multiline_string = “this\\nis\\nsome\\ntext”\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # assign string
\nmultiline_string = multiline_string.replace(‘\\n’,’\\r\\n’) # convert newlines to newlines+carriage return<\/p>\nwith open(‘xyz.csv’, ‘wb’) as outfile:
\nw = csv.writer(outfile)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # assign csv writer method
\nw.writerow([‘sometext’,multiline_string])\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # append\/write row to file<\/p>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
Within this short tutorial we will show you the steps required to create a csv file that includes multi-line cells within Python. In order to create a mutliline cell within Excel (2010\/2013) the following is required: newlines are represented with a carriage return\/newline, the string should be wrapped in quotes. One of the great things … Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"yoast_head":"\n
Create a Multiline Cell Based CSV File Within Python - Fir3net<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n