将txt文件 导入到excel中

十年热恋 提交于 2019-11-28 02:20:17

 

 

 使用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")

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!