簡體   English   中英

python如何讀取txt文件內容保存到excel

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

在一個文件夾中,有兩個文件 a.txt b.txt

a.txt有數據,a111 a222 a333

b.txt有數據,b111 b222 b333

我要他們的數據保存到excel文件一欄

是這樣的:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM