title: How can I concatenate multiple rows of excel data into one?
body: <p>I'm currently facing an issue where I need to bring all of the data shown in the images below into one line only. </p>
  
  <p><a href="https://i.stack.imgur.com/AKYbY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AKYbY.png" alt="enter image description here"></a> </p>
  
  <p>So using Python and Openpyxl, I tried to write a parsing script that reads the line and only copies when values are non-null or non-identical, into a new workbook.</p>
  
  <p>I get out of range errors, and the code does not keep just the data I want. I've spent multiple hours on it, so I thought I would ask here to see if I can get unstuck.</p>
  
  <p>I've read some documentation on Openpyxl and about making lists in python, tried a couple of videos on youtube, but none of them did exactly what I was trying to achieve.</p>
  
  <pre><code>import openpyxl
  from openpyxl import Workbook
  
  path = "sample.xlsx"
  wb = openpyxl.load_workbook(path)
  ws = wb.active
  path2 = "output.xlsx"
  wb2 = Workbook()
  ws2 = wb2.active
  
  listab = []
  rows = ws.max_row
  columns = ws.max_column
  
  for i in range (1, rows+1):
     listab.append([])
  
  cellValue = " "    
  prevCell = " "
  
  for c in range (1, rows+1):
      for r in range(1, columns+1):
          cellValue = ws.cell(row=r, column=c).value
              if cellValue == prevCell:
                  listab[r-1].append(prevCell)
              elif cellValue == "NULL":
                  listab[r-1].append(prevCell)
              elif cellValue != prevCell:
                  listab[r-1].append(cellValue)
                  prevCell = cellValue           
  
  for r in range(1, rows+1):
      for c in range (1, columns+1):
          j = ws2.cell(row = r, column=c)
          j.value = listab[r-1][c-1]
  
  print(listab)
  
  wb2.save("output.xlsx")
  </code></pre>
  
  <p>There should be one line with the below information:</p>
  
  <p>ods_service_id | service_name| service_plan_name| CPU | RAM | NIC | DRIVE |</p>