- 经验
- 3
- 分贝
- 0
- 家园分
- 15
- 在线时间:
- 4 小时
- 最后登录:
- 2024-10-10
- 帖子:
- 2
- 精华:
- 0
- 注册时间:
- 2021-5-6
- UID:
- 1585779
注册:2021-5-6
|
发表于 2021-9-22 10:38:38
|显示全部楼层
中兴ICM网管数据导出后sheet拆分脚本
-------------------------------------------------
#!/usr/bin/python
# -*- coding:utf-8 -*-
import wx
import tkinter as tk
import xlrd
import pandas as pd
import os
from tkinter import filedialog
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='', size=(516, 363),name='frame',style=541072960)
self.启动窗口 = wx.Panel(self)
self.Centre()
self.标签1 = wx.StaticText(self.启动窗口,size=(244, 61),pos=(112, 25),label='EXCEL拆分工具',name='staticText',style=2321)
标签1_字体 = wx.Font(18,74,90,400,False,'微软 YaHei UI',28)
self.标签1.SetFont(标签1_字体)
self.按钮2 = wx.Button(self.启动窗口,size=(214, 48),pos=(130, 137),label='选择文件并拆分',name='button')
self.按钮2.Bind(wx.EVT_BUTTON,self.按钮2_按钮被单击)
self.进度条1 = wx.Gauge(self.启动窗口,range=100,size=(424, 24),pos=(36, 288),name='gauge',style=4)
self.进度条1.SetValue(10)
def 按钮2_按钮被单击(self,event):
root = tk.Tk()
root.withdraw()
def excel2csv(excel_file):
# 打开excel文件
workbook = xlrd.open_workbook(excel_file)
# 获取所有sheet名字
sheet_names = workbook.sheet_names()
dir_path = os.path.abspath(os.path.dirname(excel_file))
# 获取excel当前目录
csv_path = dir_path + '\\csv\\'
# if not os.path.exists(csv_path):
os.mkdir(csv_path)
# 在excel所在目录下新建csv文件夹
for worksheet_name in sheet_names:
# 遍历每个sheet并用Pandas读取
data_xls = pd.read_excel(excel_file, worksheet_name, index_col=None)
data_xls.to_csv(csv_path + worksheet_name + '.csv', encoding='utf-8-sig')
# 把每个sheet分别存为一个csv文件
# data_xls.to_csv(csv_path+worksheet_name+'.csv',index=None,encoding='utf-8')
# data_xls.to_excel(csv_path+worksheet_name+'.xlsx',index=None,encoding='utf-8')
# data_xls.to_excel(str(worksheet_name)+".xls", sheet_name=worksheet_name, index = False)
# 获取文件路径
file_path = filedialog.askopenfilename()
o = file_path
excel2csv(o)
class myApp(wx.App):
def OnInit(self):
self.frame = Frame()
self.frame.Show(True)
return True
if __name__ == '__main__':
app = myApp()
app.MainLoop()
|
|