Merging xls into a common one

John Mathew john.mathew.python at gmail.com
Wed Oct 16 19:28:43 EDT 2013


This code works fine when there are xls in which Row has One column, but
not when Row has more column.
The expectation is to merge the different xls into a common one.
Can somebody please help.


import xlwt
import xlrd
import sys
#Create workbook and worksheet

wbk = xlwt.Workbook()
dest_sheet = wbk.add_sheet('Data_1')

for sheet_idx in range(1, 3):
    sheet = xlrd.open_workbook('Data_%d.xls' % sheet_idx).sheet_by_index(0)

    for i in range(5):
        values = sheet.row_values(i)
        for idx, element in enumerate(values):
            dest_sheet.write(i, sheet_idx+idx, element)

wbk.save('DATA.xls')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131016/d8def0c6/attachment.html>


More information about the Python-list mailing list