title: Python program to convert a text file into an Excel file
body: <p>I have a text file : </p>
  
  <pre><code>Created 30/01/2018 18:28 by Windographer 4.0.26
  
  Latitude = N 9.601639
  Longitude = E 98.476861
  Elevation = 0 m
  Calm threshold = 0 m/s
  
  Included flags: &lt;Unflagged data&gt;
  Excluded flags: Invalid
  
  Time stamps indicate the beginning of the time step.
  
  Date/Time   Ban Kong Niam [m/s] 
  2008-06-01 00:00    9999
  2008-06-01 01:00    9999
  2008-06-01 02:00    9999
  2008-06-01 03:00    9999
  2008-06-01 04:00    9999
  2008-06-01 05:00    9999
  2008-06-01 06:00    9999
  2008-06-01 07:00    9999
  2008-06-01 08:00    9999
  </code></pre>
  
  <p>Now, I want to convert this text file into an Excel file. </p>
  
  <p>I am able to write a python program for creating an excel file if the text file contains only the following lines :</p>
  
  <pre><code>Date/Time   Ban Kong Niam [m/s] 
  2008-06-01 00:00    9999
  2008-06-01 01:00    9999
  2008-06-01 02:00    9999
  2008-06-01 03:00    9999
  2008-06-01 04:00    9999
  2008-06-01 05:00    9999
  2008-06-01 06:00    9999
  2008-06-01 07:00    9999
  2008-06-01 08:00    9999
  </code></pre>
  
  <p>For that, I used the python code : </p>
  
  <pre><code>data = []
  with open("E:/Sreeraj/Thailand/1. Ban Kong Niam.txt") as f:
  for line in f:
      data.append([word for word in line.split("\t") if word])
  print data
  import xlwt
  wb = xlwt.Workbook()
  sheet = wb.add_sheet("New Sheet")
  for row_index in range(len(data)):
      for col_index in range(len(data[row_index])):
          sheet.write(row_index, col_index, data[row_index][col_index])
  wb.save("E:/Sreeraj/Thailand/hi.xls")
  </code></pre>
  
  <p>This python code worked perfectly. </p>
  
  <p>But, I want to convert entire text file into an Excel file. For, that, I want to  print : </p>
  
  <pre><code>Created 30/01/2018 18:28 by Windographer 4.0.26
  
  Latitude = N 9.601639
  Longitude = E 98.476861
  Elevation = 0 m
  Calm threshold = 0 m/s
  
  Included flags: &lt;Unflagged data&gt;
  Excluded flags: Invalid
  
  Time stamps indicate the beginning of the time step.
  </code></pre>
  
  <p>How can I make a single python program which converts the entire text file with the given below lines into an Excel file ? </p>
  
  <pre><code>Created 30/01/2018 18:28 by Windographer 4.0.26
  
  Latitude = N 9.601639
  Longitude = E 98.476861
  Elevation = 0 m
  Calm threshold = 0 m/s
  
  Included flags: &lt;Unflagged data&gt;
  Excluded flags: Invalid
  
  Time stamps indicate the beginning of the time step.
  
  Date/Time   Ban Kong Niam [m/s] 
  2008-06-01 00:00    9999
  2008-06-01 01:00    9999
  2008-06-01 02:00    9999
  2008-06-01 03:00    9999
  2008-06-01 04:00    9999
  2008-06-01 05:00    9999
  2008-06-01 06:00    9999
  2008-06-01 07:00    9999
  2008-06-01 08:00    9999
  </code></pre>