简体   繁体   中英

Can we parse .txt file and copy multiline parsed text to excel cell using python?

I am new to python. I have a data in.txt that repeats after start and end texts. eg start line (always same character), some text lines below start line and finally end line. This pattern continues. Every end line is followed by 2 hard enters, then new start line starts. I believe it can be used as a delimiter.

I am looking to write something that can parse start to end lines (multi lines) and copy that to excel cell. So, excel cell will have all parsed multiline texts in 1 column. For instance, cell A1 may have 5 line parsed text, A2 may have 7 line and so on depending on the parsed value from.txt files.

I have gone though many forums but still unsure how to do it. I will appreciate the help.

@Sam K, I would suggest saving the.txt file as.csv file and adding double quote to indicate multiline row entry.

example of csv file content:

"TEST
1
2
3",
"TEST
4
5
6"

it will be rendered in excel as excel rendered rows

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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