Python Forum
Merging excel worksheets with balnk rows - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Merging excel worksheets with balnk rows (/thread-26935.html)



Merging excel worksheets with balnk rows - sauravksingh85 - May-19-2020

Hi,

There is a task where I have to merge multiple excel spread sheets. The column number do not start from the first column and it can lie & start from any where or row in the spreadsheet.
There are blank rows in between data points which needs to be copied.

045401 641378-2019 2019079763 186851 2019-10-24 2019-10-27 EUR 5,919.58
045401 641379-2019 2019079764 190110 2019-10-24 2019-10-27 EUR 64.56



212716 00247743-2019 201910323 124320 2019-10-01 2019-10-01 EUR 61,001.44
212716 00248118-2019 201910680 128698 2019-10-09 2019-10-09 EUR 58,671.33

I donot want these rows to be copied to my destination or target excel file. I am using openpyxl and have trying to avoid these rows by using 'None' to identify blankrows but this logic is not working.
Code--
for row in range(a,ws1.max_row):      
         colnum=3
         for j in range(2,9):
              if ws1.cell(a,1).value != None:    
                  c=ws1.cell(row,j)                 
                  ws2.cell(rownumber,colnum).value=c.value
                  colnum=colnum+1
              else:
                  break;
         rownumber=rownumber+1



RE: Merging excel worksheets with balnk rows - sauravksingh85 - May-19-2020

ANy help on this will be appreciated