Created
February 3, 2014 08:50
-
-
Save skitazaki/8780675 to your computer and use it in GitHub Desktop.
Bind multiple TSV files into Excel workbook.
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/env python3 | |
# -*- coding: utf-8 -*- | |
"""Bind multiple TSV files into Excel workbook. | |
Requires "xlwt" for Python 2.x, or "xlwt-future" for Python 3.x series. | |
""" | |
import os | |
import sys | |
from xlwt import Workbook | |
DELIMITER = '\t' | |
OUTPUT = 'book.xls' | |
def main(): | |
book = Workbook() | |
for f in sys.argv[1:]: | |
sheet = book.add_sheet(os.path.splitext(os.path.basename(f))[0]) | |
stream = map(lambda l: l.rstrip('\r\n').split(DELIMITER), open(f)) | |
for i, row in enumerate(stream): | |
for j, v in enumerate(row): | |
sheet.write(i, j, v) | |
book.save(OUTPUT) | |
if __name__ == '__main__': | |
main() | |
# vim: set et ts=4 sw=4 cindent fileencoding=utf-8 : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment