简体   繁体   English

我们可以使用 python 解析.txt 文件并将多行解析文本复制到 excel 单元格吗?

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

I am new to python.我是 python 的新手。 I have a data in.txt that repeats after start and end texts.我有一个在开始和结束文本之后重复的数据 in.txt。 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.每条结束线后面跟着 2 个硬输入,然后新的开始线开始。 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.我正在寻找可以解析开始到结束行(多行)并将其复制到 excel 单元格的东西。 So, excel cell will have all parsed multiline texts in 1 column.因此,excel 单元格将在 1 列中包含所有已解析的多行文本。 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.例如,单元格 A1 可能有 5 行解析文本,A2 可能有 7 行,依此类推,具体取决于来自 .txt 文件的解析值。

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. @Sam K,我建议将 .txt 文件另存为 .csv 文件并添加双引号以指示多行行条目。

example of csv file content: csv 文件内容示例:

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

it will be rendered in excel as excel rendered rows它将在 excel 中呈现为excel 呈现的行

Hope this helps.希望这可以帮助。

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

相关问题 使用python将文本文件(对象)作为.txt插入到Excel工作表的单元格中 - Insert a text file (object) as .txt into a cell of excel sheet using python 使用Parsimonious Python库解析多行文本 - Parse multiline text using the Parsimonious Python library 解析 Excel 单元格中的文本并使用 python 提取日期 - Parse a text in an Excel cell and extract date using python 使用python在txt文件中进行多行搜索 - Multiline search in txt file with python Python从多个txt文件解析文本 - Python parse text from multiple txt file 未使用 python 解析文本文件的更新 - Updates to text file are not being parsed using python 我们如何使用 python 正则表达式解析文本? - How can we parse the text using python regex? 有什么方法可以将 Excel 文件中列的值与使用 Python 的文本文件的内容进行比较? - Is there any way in which we can compare the values from a column in excel file with the contents of text files using Python? 如何使用 Python 解析 txt 文件并从 txt 文件的特定部分创建字典? - How can I parse a txt file and create dictionary from a specific part of the txt file using Python? 我们可以从 AWS S3 复制图像并将其写入 excel 文件 (S3) 而不使用 Python 将数据存储在本地吗? - Can we copy image from AWS S3 and write it into excel file (S3) without storing the data locally using Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM