-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsv_To_exel.py
37 lines (31 loc) · 1.3 KB
/
csv_To_exel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import csv, os
import xlsxwriter
csvs = '/Users/MWK/Desktop/bios/multi_bios.csv'
xlsx = '/Users/MWK/Desktop/bios/new_multi_bios.xlsx'
workbook = xlsxwriter.Workbook(xlsx)
worksheet = workbook.add_worksheet()
with open(csvs, mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
line_count = 0
for row in csv_reader:
if line_count == 0:
worksheet.write(line_count, 0, "Titel")
worksheet.write(line_count, 1, "Start tijd")
worksheet.write(line_count, 2, "Leeftijd")
worksheet.write(line_count, 3, "Afbeelding")
line_count += 1
print(f'\tDe film {row["Titel"]} begint om {row["Start tijd"]} en heeft als url{row["Afbeelding"]}')
if "(OV)" in str(row["Titel"]):
worksheet.write(line_count, 4, "True")
else:
worksheet.write(line_count, 4, "False")
worksheet.write(line_count, 0, str(row["Titel"]))
worksheet.write(line_count, 1, str(row["Start tijd"]))
try:
worksheet.write(line_count, 2, int(row["Leeftijd"]))
except ValueError as e:
worksheet.write(line_count, 2, str(row["Leeftijd"]))
worksheet.write(line_count, 3, str(row["Afbeelding"]))
line_count += 1
print(f'Processed {line_count} lines.')
workbook.close()