python convert csv to xlsx

搬运:http://stackoverflow.com/questions/17684610/python-convert-csv-to-xlsx

import os
import glob
import csv
from xlsxwriter.workbook import Workbook


for csvfile in glob.glob(os.path.join('.', '*.csv')):
    workbook = Workbook(csvfile + '.xlsx')
    worksheet = workbook.add_worksheet()
    with open(csvfile, 'rb') 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()

xls库:xlsxwriter ,此库简单

pypi:https://pypi.python.org/pypi/XlsxWriter/0.6.8

 

  

posted @ 2016-05-11 16:50  放在垃圾桶里  阅读(1075)  评论(0编辑  收藏  举报