forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_excel.py
68 lines (48 loc) · 1.42 KB
/
csv_excel.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import openpyxl
import sys
csv_name = input("Name of the input CSV file with extension: ")
sep = input("Separator of the CSV file: ")
ename = input("Name of the output excel file with extension: ")
sname = input("Name of the output excel sheet: ")
try:
workbook = openpyxl.load_workbook(ename)
sheet = workbook.get_sheet_by_name(sname)
file = open(csv_name, "r", encoding="utf-8")
except:
print("Error: File not found")
sys.exit()
excel_row = 1
excel_column = 1
for lines in file:
lines = lines[:-1]
lines = lines.split(sep)
for dat in lines:
sheet.cell(excel_row, excel_column).value = dat
excel_column += 1
excel_column = 1
excel_row += 1
workbook.save(ename)
file.close()
csv_name = input("Name of the input CSV file with extension: ")
sep = input("Separator of the CSV file: ")
ename = input("Name of the output excel file with extension: ")
sname = input("Name of the output excel sheet: ")
try:
workbook = openpyxl.load_workbook(ename)
sheet = workbook.get_sheet_by_name(sname)
file = open(csv_name, "r", encoding="utf-8")
except:
print("Error: File not found")
sys.exit()
excel_row = 1
excel_column = 1
for lines in file:
lines = lines[:-1]
lines = lines.split(sep)
for dat in lines:
sheet.cell(excel_row, excel_column).value = dat
excel_column += 1
excel_column = 1
excel_row += 1
workbook.save(ename)
file.close()