title: Read Value of Columns in Excel
body: <p>I want to insert values from Python into an Excel sheet. I can't figure out the way to go about this. I would like to make a for-loop to determine the last entry in column[0] (vertically) in my Excel sheet. This is my python code:</p>
  <pre><code># Modules
  import datetime, os, sys, json, requests, time, openpyxl, xlrd, xlwt
  from itertools import count
  import urllib.request as request
  from urllib.parse import urlparse, parse_qs
  from openpyxl import Workbook
  from openpyxl import load_workbook
  from xlwt import Workbook
  from cgitb import text
  from re import X
  from flask import Flask, request, render_template
  from datetime import datetime, time, date
  
  #Flask Constructor
  app = Flask(__name__)
  
  #Main Function
  @app.route('/')
  def main():
      return render_template('index.html')
  
  #Excel Convert Function
  @app.route('/initiate_excel_corvert',  methods=['GET', 'POST'])
  def initiate_excel_corvert():
      
      #Get URL
      id = request.args.get('ID')
  
      #Sort Values From URL
      a = id.split('_*_')[0]
      b = id.split('_*_')[1]
      c = id.split('_*_')[2]
      d = id.split('_*_')[3]
  
      #Counter
      counter1 = 1
      A_counter = 0
  
      #Excel Variables
      dest_filename = 'empty_book.xlsx'
      dest_filename_sheet = 'Sheet 1'
  
      #Openpyxl Workbook
      wb = Workbook()
      sheet1 = wb.add_sheet('Sheet 1')
  
      #Insert Headlines for Cells into Excel
      sheet1.write(0, 0, &quot;0&quot;)
      sheet1.write(0, 1, &quot;a&quot;)
      sheet1.write(0, 2, &quot;b&quot;)
      sheet1.write(0, 3, &quot;c&quot;)
      sheet1.write(0, 4, &quot;d&quot;)
  
      #Save Result    
      wb.save(dest_filename)
      print(str(&quot;Complete&quot;))
      print(&quot;\n&quot;)
  
      book = xlrd.open_workbook('empty_book.xlsx')
      sheet = book.sheet_by_index(0)
  
      #Count of rows
      count = 0
      for row in range(sheet.nrows):
          for col in sheet.row_values(row):
              if col.strip() != '':
                  count += 1
              print(count)
  
      #Insert into file.txt
      with  open(&quot;python.txt&quot;, &quot;a&quot;) as file:
          content = str(Tid) + '_' + str(id) + '\n'
          print(&quot;Appended!&quot;)
          file.write(content)
          file.close()
  
  
      workbook = xlrd.open_workbook(&quot;empty_book.xlsx&quot;, &quot;rb&quot;)
      sheets = workbook.sheet_names()
      sh = workbook.sheet_by_name(dest_filename_sheet)
      for rownum in range(0, sh.nrows): #skipping header of the xlsx
          xz = sh.cell(rownum, 0)
          xz_int = int(xz.value)
          print(xz_int)
          print(&quot;\n&quot;)
          if xz_int == counter1:
              counter1 += 1
              print(&quot;Hi Mathematics0&quot;)     
          else:
              xz_int += 1
              print(&quot;Swag&quot;)
              print(&quot;\n&quot;)
  
          if xz_int == counter1:
              print(&quot;Hi Mathematics1&quot;)
              #Insert posted values
              sheet1.write(counter1, 0, str(a))
              sheet1.write(counter1, 1, str(b))
              sheet1.write(counter1, 2, str(c))
              sheet1.write(counter1, 3, str(d))
              wb.save(dest_filename)
              print(&quot;Inserted into1&quot;)
              print(&quot;\n&quot;)
              counter1 += 1
              xz_int += 1
          if xz_int == counter1:
              print(&quot;Hi Mathematics2&quot;)
              print(&quot;\n&quot;)  
              sheet1.write(counter1, 0, str(a))
              sheet1.write(counter1, 1, str(b))
              sheet1.write(counter1, 2, str(c))
              sheet1.write(counter1, 3, str(d))
              wb.save(dest_filename)
              print(&quot;Inserted into&quot;)
              counter1 += 1
              xz_int += 1
          else:
              print(&quot;Swag2&quot;)
              print(&quot;\n&quot;)
  
      return render_template('index.html')
  
  
  
  ## END_end
  </code></pre>
  <p>I want to be able to read the current index in column[0, X] in the file.xlms and create an entry to the position/value of column[0, X+1]. The current Excel-result and terminal output I be getting are:</p>
  <p><a href="https://i.stack.imgur.com/MQ2xY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MQ2xY.png" alt="Excel Result" /></a></p>
  <p>I know it's my for loop that's too crazy. But I hope you get the idea of what I'm trying to do. I want to add new lines in Excel with the values from every entry, also without deleting the old ones. Thanks anyway :)</p>