I need help, I can’t figure out what I need to do.
The task is as follows, I need to be able to select multiple xlsx files and convert them to csv.
In my code I got the ability to do this with only one file. I hope for your help and advice. Thanks
JavaScript
x
27
27
1
path_file = sg.popup_get_file('Choose files',
2
3
title='Choose files',
4
5
file_types=(('Excel Files', '*.xlsx'),),
6
7
multiple_files=True)
8
9
df = pd.read_excel(path_file, dtype='str', engine='openpyxl')
10
11
new_header = []
12
13
for i in list(df.columns):
14
15
new_header.append(i.upper())
16
17
df.columns = new_header
18
19
for col in df.columns:
20
21
df[col] = df[col].str.replace('"', '')
22
23
24
25
df.to_csv(path_file[:-5] + '.csv',index=False, encoding='utf-8', sep=';', lineterminator='rn')
26
27
Advertisement
Answer
Without option no_window=True
, it will return None or str-type filepaths with separator ';'
between each file_path.
JavaScript
1
14
14
1
import PySimpleGUI as sg
2
3
path_files = sg.popup_get_file(
4
'Choose files',
5
title='Choose files',
6
file_types=(('Excel Files', '*.xlsx'),),
7
multiple_files=True,
8
)
9
if path_files:
10
for path_file in path_files.split(';'):
11
print(path_file) # Do the conversion here
12
else:
13
print('No file selected !')
14