Created
December 16, 2014 03:59
-
-
Save zfogg/ee194919a09660f7640d to your computer and use it in GitHub Desktop.
Convert a folder of CSVs into an Excel workbook, one worksheet per file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""CSVsToWorksheets.py: takes a folder of CSVs and puts them into a single Excel workbook, one worksheet per file.""" | |
__author__ = "Zach Fogg" | |
__email__ = "[email protected]" | |
import xlwt, csv, os | |
csv_folder = "Output/" | |
book = xlwt.Workbook(encoding="utf8") | |
for fil in os.listdir(csv_folder): | |
name = fil[:-18] # FIXME - clip the filenames to your liking | |
sheet = book.add_sheet(name) | |
with open(csv_folder + fil) as filname: | |
reader = csv.reader(filname) | |
i = 0 | |
for row in reader: | |
for j, each in enumerate(row): | |
sheet.write(i, j, each) | |
i += 1 | |
book.save("Output.xls") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment