Skip to content

Instantly share code, notes, and snippets.

@skitazaki
Created February 3, 2014 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skitazaki/8780675 to your computer and use it in GitHub Desktop.
Save skitazaki/8780675 to your computer and use it in GitHub Desktop.
Bind multiple TSV files into Excel workbook.
#!/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