File tree 1 file changed +68
-0
lines changed
1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ import openpyxl
2
+ import sys
3
+
4
+ csv_name = input ("Name of the input CSV file with extension: " )
5
+ sep = input ("Separator of the CSV file: " )
6
+ ename = input ("Name of the output excel file with extension: " )
7
+ sname = input ("Name of the output excel sheet: " )
8
+ try :
9
+ workbook = openpyxl .load_workbook (ename )
10
+ sheet = workbook .get_sheet_by_name (sname )
11
+
12
+ file = open (csv_name , "r" , encoding = "utf-8" )
13
+ except :
14
+ print ("Error: File not found" )
15
+ sys .exit ()
16
+ excel_row = 1
17
+ excel_column = 1
18
+
19
+ for lines in file :
20
+
21
+ lines = lines [:- 1 ]
22
+ lines = lines .split (sep )
23
+
24
+ for dat in lines :
25
+
26
+ sheet .cell (excel_row , excel_column ).value = dat
27
+
28
+ excel_column += 1
29
+
30
+ excel_column = 1
31
+ excel_row += 1
32
+
33
+
34
+ workbook .save (ename )
35
+ file .close ()
36
+
37
+ csv_name = input ("Name of the input CSV file with extension: " )
38
+ sep = input ("Separator of the CSV file: " )
39
+ ename = input ("Name of the output excel file with extension: " )
40
+ sname = input ("Name of the output excel sheet: " )
41
+ try :
42
+ workbook = openpyxl .load_workbook (ename )
43
+ sheet = workbook .get_sheet_by_name (sname )
44
+
45
+ file = open (csv_name , "r" , encoding = "utf-8" )
46
+ except :
47
+ print ("Error: File not found" )
48
+ sys .exit ()
49
+ excel_row = 1
50
+ excel_column = 1
51
+
52
+ for lines in file :
53
+
54
+ lines = lines [:- 1 ]
55
+ lines = lines .split (sep )
56
+
57
+ for dat in lines :
58
+
59
+ sheet .cell (excel_row , excel_column ).value = dat
60
+
61
+ excel_column += 1
62
+
63
+ excel_column = 1
64
+ excel_row += 1
65
+
66
+
67
+ workbook .save (ename )
68
+ file .close ()
You can’t perform that action at this time.
0 commit comments