通信人家园
标题:
中兴ICM网管数据导出拆分【python】
[查看完整版帖子]
[打印本页]
时间:
2021-9-22 10:38
作者:
xd199677
标题:
中兴ICM网管数据导出拆分【python】
中兴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,
'Microsoft 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()
通信人家园 (https://www.txrjy.com/)
Powered by C114