import pandas as pd
import os
#获取excl
excl_files = []
path = os.getcwd()
print(path)
files = os.listdir(path)
print(files)
for file in files:
# print(file.split(".")[-1])
if file.split(".")[-1] == 'xlsx' or file.split(".")[-1] == 'xls':
excl_files.append(file)
print(excl_files)
#创建文件夹
input_dir = os.path.exists('csv')
if input_dir is False:
os.mkdir('csv')
print(input_dir)
#读取文件
for excl_file in excl_files:
print(excl_file)
datas = pd.read_excel(excl_file,sheet_name=None)
print(datas)
#转换文件
for name,data in datas.items():
print(name)
print(data)
input_name = excl_file.split('.')[0]+'_'+name+'.csv'
csv_path = os.path.join(path,'csv',input_name)
if not data.empty:
data.to_csv(csv_path,encoding='utf-8',index=False)
#把脚本放在需要处理的文件加下运行就好了