简体   繁体   English

python如何读取txt文件内容保存到excel

[英]How does python read the content of txt file and save it in excel

in one folder, there are two files a.txt b.txt在一个文件夹中,有两个文件 a.txt b.txt

a.txt has data, a111 a222 a333 a.txt有数据,a111 a222 a333

b.txt has data, b111 b222 b333 b.txt有数据,b111 b222 b333

I want their data to save into the excel file one column我要他们的数据保存到excel文件一栏

Something like this:是这样的:

from openpyxl import load_workbook
from openpyxl import Workbook
wb = load_workbook(filename = "your.xlsx")
ws = wb.activewith 
row1 = 1
open("demo.txt") as file:
for item in file:
    ws.cell(row=row1, column=1).value = item
    row1 = row1 + 1

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

相关问题 python读取excel文件并从excel中保存带有标题和内容的N个txt文件 - python read excel file and save N txt files with title and content from excel 如何使用python读取.txt文件的内容? - how to read the content of .txt file using python? 如何将从.txt文件中读取的这些元素保存到python中的数组/矩阵中 - How to save these elements read from a .txt file into an array/matrix in python Python中如何逐行读取.txt文件的内容 - How to read the content of .txt file line by line in Python Python 读取txt文件并将其保存为 json 与密钥 - Python read txt file and save it as json with keys 如何在 Python 中读取、编辑和另存为另一个 excel 文件? - How to read, edit, and save as another excel file in Python? 如何在python中读取文件并将其内容保存为二维数组? - How to read a file in python and save its content to a two dimensional array? 如何读取一个excel文件并将内容转换为python中的列表列表? - how to read an excel file and convert the content to a list of lists in python? 如何读取带有数据块的复杂txt文件并将其另存为python中的csv文件? - How to read complex txt file with blocks of data and save it as csv file in python? Python-使用模块搁置将文件txt的内容保存在数据库中 - Python - Save content of a file txt in a db with module shelve
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM