I am trying to combine multiple csv files into one excel file whereby each file is it’s own sheet in the xls file.
Below is a python script that can convert all csv files in a folder into there respective excel files.
import os
import glob
import csv
from xlsxwriter.workbook import Workbook
"""with open('output.csv', "rt", encoding = 'UTF-8') as fin:
with open('outputconvert.csv', "wt", encoding = 'UTF-8') as fout:
for line in fin:
fout.write(line.replace(';',','))"""
for csvfile in glob.glob(os.path.join('.', '*.csv')):
workbook = Workbook(csvfile[:-4] + '.xlsx')
worksheet = workbook.add_worksheet('testws')
with open(csvfile, 'rt', encoding='utf8') as f:
reader = csv.reader(f)
for r, row in enumerate(reader):
for c, col in enumerate(row):
worksheet.write(r, c, col)
workbook.close()
It works fine, but is there a way I can expand it such that it can merge files into one file and each file is in a separate worksheet
Thanks in advance