import xlwt
import numpy as np
import os
import re
def read_txt(path):
filelist = os.listdir(path)
file_names = np.array([file for file in filelist if file.endswith('.txt')], dtype=object)
return file_names
workbook = xlwt.Workbook()
path = './MVK-Gauge-54'
sheet1 = workbook.add_sheet('result', cell_overwrite_ok=True)
sheet1_row = read_txt(path)
for i in range(len(sheet1_row)):
sheet1.write(0, i, sheet1_row[i])
paths = path + '/' +sheet1_row[i]
f = open(paths)
lines = f.readlines()
lines_list = lines[6:]
index = 1
lsat_list = []
for line in lines_list:
data = line.strip().split(" ")
for val in data:
val = val.split(' ')
val = [x for x in val if x != '']
for key in val:
key = float(key)
sheet1.write(index,i, key)
index += 1
workbook.save('test.xls')