Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'element': 0.07; 'sys': 0.07; 'expectation': 0.09; 'subject:into': 0.09; '#create': 0.16; '3):': 0.16; 'idx,': 0.16; 'xlrd': 0.16; 'help.': 0.21; '8bit%:5': 0.22; 'import': 0.22; 'merge': 0.24; 'fine': 0.24; 'values': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:one': 0.36; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'more': 0.64; 'different': 0.65; 'column.': 0.84; 'subject:common': 0.84; 'sheet': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=SgGJ15ixNIUUYhGyt9sZQGdEoBLtuymssOI6W46aFNQ=; b=M6ukRHtwjwxON5IPgQYZZDz3Ij8IP+MvH0lvgWhJeKEeWvQ7xl4E+jmNc2NOCRcPLu /ucPtz2kN3R69GUkP4Wrp36qlSCgyfRVa1hxaLh5pQO5cLkJ7JXHa3TotdmaQWs3WrPW VjbRgOShx+jzcIj1aE1oJO0q41TMVGku63SEK8drlDYE1V4kKcdMQkgR1hrhi3TFoaHh A6HrxIde92UFHfnMbVp1s/3MCNda59scY2LQ++t8A5wP/rS0T38C3GfsCkAahuhlgxSu WB3XvQZ0S08J5r+nLg4XPb8jMz/VYcE8dCrvyDcHNZ3+i+7FZr32nnPM+GzbDFdm1xzR L4Jw== MIME-Version: 1.0 X-Received: by 10.14.113.137 with SMTP id a9mr8366292eeh.3.1381966123253; Wed, 16 Oct 2013 16:28:43 -0700 (PDT) Date: Wed, 16 Oct 2013 16:28:43 -0700 Subject: Merging xls into a common one From: John Mathew To: python-list@python.org Content-Type: multipart/alternative; boundary=001a1133a718de631904e8e40f4e X-Mailman-Approved-At: Thu, 17 Oct 2013 03:16:17 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381972578 news.xs4all.nl 15884 [2001:888:2000:d::a6]:40588 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56925 --001a1133a718de631904e8e40f4e Content-Type: text/plain; charset=ISO-8859-1 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') --001a1133a718de631904e8e40f4e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
This code works fine when there are xls in which Row has O= ne column, but not when Row has more column.=A0
The expectation is to m= erge the different xls into a common one.
Can somebody please hel= p.


import xlwt
import xlrd
import sys
#Create workbook and worksheet

=
wbk =3D xlwt.Workbook()
dest_sheet =3D wbk.add_sheet(&= #39;Data_1')

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

=A0 =A0 for i in range(5):
=A0 =A0 =A0 = =A0 values =3D sheet.row_values(i)
=A0 =A0 =A0 =A0 for idx, element in enumerate(values):
=A0 = =A0 =A0 =A0 =A0 =A0 dest_sheet.write(i, sheet_idx+idx, element)
<= br>
wbk.save('DATA.xls')
--001a1133a718de631904e8e40f4e--