[Python-Excel](01)Excel列数据提取到TXT文件
前言:
将Excel中列数据以特定的格式另存为TXT中,方便其他软件格式导入
如需要:“数据列A”+ “,”+ “数据列B” 格式
实现:
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import datetime
import pandas as pd
import numpy as nppd.set_option('display.width', 100)
pd.set_option('precision', 0)
pd.set_option('expand_frame_repr', False)
def env_show1():messagebox.showinfo(title = "反馈",message= "by 张繁同学 \n意见邮箱:daji_1967@163.com \nbilibili:点星星的灯")
#---------文件选框-------------
def selectFile():global filepathfilepath = filedialog.askopenfilename(filetypes = [('XLSX','*.xlsx'),('XLS','*.xls'),('ALL FILES','*')])select_path.set(filepath)
#文件打开
def dif():file1 = pd.read_excel(filepath,header=0, # 指定行作为头#sheet_name=1, # 可表示为 sheet_name=‘sheet’具体名字;也可以sheet_name = [0,1]#usecols="A:J",)num_row, num_colu = file1.shape # 获取当前最大行列#文件新建在当前.PY文件所在的文件夹with open('./简易清单{}.txt'.format(datetime.datetime.now().strftime("%H_%M_%S")), encoding='utf-8', mode='w') as w1:w1.write('Code,Name\n')for i in range(num_row):a = list(file1['姓名'])b = list(file1['考试编号'])w1.write('{},{}\n'.format(b[i].replace(' ',''), a[i]))messagebox.showinfo("Info", " 完成!")
win = tk.Tk()
win.resizable(True, True) # 窗口大小可调(长 /宽)
# 获取当前分辨率
screenwidth = win.winfo_screenwidth()
screenheight = win.winfo_screenheight()
# print(type(screenheight))
win.geometry('450x200+{}+{}'.format(int(screenwidth / 3), int(screenheight / 3)))
win.title('Excel转txt')
win.attributes("-alpha",1)#设置透明度
# canvas = tk.Canvas(win,bg = 'pink')
# canvas.pack()
select_path = tk.StringVar()
but1 = tk.Button(win, text='文件选择', command=lambda: selectFile())
but1.place(x=300, y=50, width=100, height=20)but2 = tk.Button(win, text='转txt', command=lambda: dif())
but2.place(x=300, y=110, width=100, height=20)
but2 = tk.Button(win, text='2')entry1 = tk.Entry(win, textvariable=select_path)
entry1.place(x=50, y=50, width=240, height=20) # 大小调节放到这entry2 = tk.Entry(win, textvariable=None,state = 'disabled')
entry2.place(x=50, y=80, width=240, height=20) # 大小调节放到这
entry3 = tk.Entry(win, textvariable=None,state = 'disabled')
entry3.place(x=50, y=110, width=240, height=20) # 大小调节放到这menubar = tk.Menu(win) #创建一个父容器
#先添加下拉窗口# menubar.add_command(label = "Quit", command = win.quit)
# menubar.add_command(label = "Open", command = lambda :None)
win['menu'] = menubarwin.mainloop()
效果图:
→
学一点,记一点。鱼翻藻鉴,鹭点烟汀。
[Python-Excel](01)Excel列数据提取到TXT文件相关推荐
- 将指定excel的一列数据提取到另一个excel的指定列
#!/usr/bin/env python import openpyxl bj='D:/地市县公司/西藏台账数据分析-设备台帐分析.xlsx' wb = openpyxl.load_workbook ...
- python excel取列_python取excel表格第一列数据-python操作excel,使用xlrd模块,获取某一列数据的......
怎样用python,读取excel中的一列数据 Python对Excel的读写主要有xlrd.copyxlwt.xlutils.openpyxl.xlsxwriter几种. 1.xlrd主要用来读百取 ...
- python excel增加一列_(用Python修改excel中一列数据)python新增一列
python怎么从excel中读取数据? ⒈ #import παέτο import xlrd #Ρύθμι διαδρής path='C:\\Users\\jyjh\\Desktop\\data ...
- python3读取excel某一列_怎样用python,读取excel中的一列数据!python读取excel某一列数据...
Python 如何循环读取csv或者excel中的一列数据,写入到中搜索 是可以 a.csv复制到 b.csv中 import csv def foo(): with open('a.csv', 'r ...
- python利用表格中的某一个列_python取excel表格第一列数据?python操作excel,使用xlrd模块,获取某一列数据的语句为...
用Python修改excel中一列数据 可以使用pandas库,先读取excel文件,然后使用pandas库来修改一列,然后写入文件即可. 怎样用python,读取excel中的一列数据 sheet. ...
- python给excel排序_使用Python对Excel中的列数据进行排序
有没有办法从excel表格中获取列,将列写入列表并将其排序,然后将它们重写为另一个Excel表格?这是我到目前为止所尝试的,但它只写入最后一列数据.我不需要前两行数据,因为它们只是标题.使用Pytho ...
- 提取Excel某一列数据并统计出现次数,绘制扇形图
数据提取--提取Excel某一列数据 xlrd库读取Excel表 .xls后缀 打开需要读的.xls表,获取需要的列.循环求次数,不返回列名(不需要列名数据). 按照出现次数值,降序排序. 循环查看 ...
- 用python读取excel指定的列数据
可以使用Python中的Pandas库来帮助你读取Excel指定的列数据.可以使用pandas.read_excel()函数,并指定要读取的列名称:df = pandas.read_excel(文件名 ...
- 如何排两列的序计算机考试,excel中两列数据怎么一起排序?excel两列同时排序的方法...
excel中两列数据怎么一起排序?excel两列同时排序的方法 腾讯视频/爱奇艺/优酷/外卖 充值4折起 我们在使用Excel对数列排序时,有时会碰到需要对两列数据同时排序,下面就跟大家详细介绍操作方 ...
最新文章
- Apache服务器部署(1)
- 三步问题(求n中方式)
- 金融风控--申请评分卡模型--特征工程(特征分箱,WOE编码) 标签: 金融特征分箱-WOE编码 2017-07-16 21:26 4086人阅读 评论(2) 收藏 举报 分类: 金融风
- C语言中指针的使用方法
- 分布式系统理论基础 - 一致性、2PC和3PC
- 原型磨刀 开源一样的_晚餐也可以像开源一样
- 【LeetCode】217. Contains Duplicate (2 solutions)
- @Value(#{})与@Value(${})的区别
- 5年迭代5次,抖音推荐系统演进历程
- linux的pascal语言,pascal语言视频教程 Linux GCC常用命令详解
- Roslyn 入门:使用 Roslyn 静态分析现有项目中的代码
- stm32单片机学习秘籍(完整版)
- 体系结构复习2——指令级并行(分支预测和VLIW)
- Pandas如何读取保存Excel
- SAP ALV报表开发实战案例(三)
- 员工转正申请书_员工转正申请书简短的
- 关于C语言教材的一点疑惑。为什么现在国内各大高校仍选用谭浩强的《C 程序设计》为教材?
- 除非p否则q 除非P否则非Q 只有p才q 彻底搞懂离散数学命题符号化的逻辑 附公务员真题讲解
- 奇瑞新能源又一款新车上市 奇瑞无界Pro炫酷来袭
- 曦力DVD备份及转换软件 Xilisoft DVD Ripper Ultimate 6绿色版