将txt文件 导入到excel中

 

 

 使用excel时 使用cmd打开命令界面后 输入 pip install openpyxl 进行在线安装

将txt文件中的导入到excel中 

import openpyxl as op
import json
file="e://stock01.txt"
b={}
with open(file,"r") as f:
    content=f.readlines()
    # print("content",content)
    for x in content:
        if x!="\n":
            c=x.split("(")
            d=c[0]
            e=c[1].replace(")\n","")
            b[e]=d

    wb=op.Workbook()
    sheet1=wb.active
    sheet1.title="yy"
    for i,(j,k)in enumerate(b.items()):

        sheet1.cell(row=i+1,column=1,value=j)
        sheet1.cell(row=i+1,column=2,value=k)
    wb.save("e://test10.xlsx")

 

转载于:https://www.cnblogs.com/gaoyuanyuan/p/9494078.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值