-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
executable file
·26 lines (23 loc) · 1.09 KB
/
convert.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
######################################################################
# Anes B. - 2016
# A very simple Python CSV to Excel (.xlsx - 2007+) sheet converter.
######################################################################
import csv
import os, glob
import sys
import xlsxwriter
if __name__ == '__main__':
#listOfFiles = os.listdir(directory) # list of all files in the directory
listOfFiles = glob.glob("*.csv")
for index, fileInList in enumerate(listOfFiles):
fileName = fileInList[0:fileInList.find('.')]
excelFile = xlsxwriter.Workbook(fileName + '.xlsx')
worksheet = excelFile.add_worksheet()
#with open(fileName + ".csv", 'rb') as f:
with open(fileInList, 'rb') as f:
content = csv.reader(f)
for index_row, data_in_row in enumerate(content):
for index_col, data_in_cell in enumerate(data_in_row):
worksheet.write(index_row, index_col, data_in_cell)
excelFile.close()
print " === Conversion is done ==="