I have a text file :
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: <Unflagged data>
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
Now, I want to convert this text file into an Excel file.
I am able to write a python program for creating an excel file if the text file contains only the following lines :
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
For that, I used the python 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")
This python code worked perfectly.
But, I want to convert entire text file into an Excel file. For, that, I want to print :
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: <Unflagged data>
Excluded flags: Invalid
Time stamps indicate the beginning of the time step.
How can I make a single python program which converts the entire text file with the given below lines into an Excel file ?
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: <Unflagged data>
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