title: Using python to add a text file to existing Excel Workbook
body: <p>Apologies if this is a basic question, but let us say I have a tab delimited file named <code>file.txt</code> formatted as follows:</p>
  
  <pre><code>Label-A    [tab]    Value-1
  
  Label-B    [tab]    Value-2
  
  Label-C    [tab]    Value-3
  
  [...]
  
  Label-i    [tab]    Value-n
  </code></pre>
  
  <p>I want <a href="https://pypi.python.org/pypi/xlrd" rel="nofollow">xlrd</a> or <a href="http://pythonhosted.org/openpyxl/" rel="nofollow">openpyxl</a> to add this data to the excel worksheet named <code>Worksheet</code> in the file <code>workbook.xlsx</code> such that the cells contain the following values. I do not want to affect the contents of any other part of <code>workbook.xlsx</code> other than the two columns that are affected</p>
  
  <pre><code>A1=Label-A
  
  B1=Value-1
  
  A2=Label-B
  
  B2=Value-2
  
  [etc.]
  </code></pre>
  
  <p>EDIT: Solution</p>
  
  <pre><code>import sys
  import csv
  import openpyxl
  
  tab_file = sys.stdin.readlines()
  
  reader = csv.reader(tab_file, delimiter='\t')
  first_row = next(reader)
  num_cols = len(first_row)
  
  try:
      workbook = sys.argv[1]
      write_sheet = sys.argv[2]
  except Exception:
      raise sys.exit("ERROR")
  
  try:   
      first_col = int(sys.argv[3])
  except Exception:
      first_col = 0
  
  tab_reader = csv.reader(tab_file, delimiter='\t')
  xls_book = openpyxl.load_workbook(filename=workbook)
  sheet_names = xls_book.get_sheet_names()
  xls_sheet = xls_book.get_sheet_by_name(write_sheet)
  for row_index, row in enumerate(tab_reader):
      number = 0
      col_number = first_col
      while number &lt; num_cols:
          cell_tmp = xls_sheet.cell(row = row_index, column = col_number)
          cell_tmp.value = row[number]
          number += 1
          col_number += 1
  xls_book.save(workbook)
  </code></pre>