You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import pandas as pd
|
|
|
|
# file_path = 'C:/GIT/SingleStation/ini/Protocol2'
|
|
|
|
# df = pd.read_xml(file_path)
|
|
def prtc2excel(*arg):
|
|
file_path = arg[0]
|
|
values = []
|
|
lens = []
|
|
state = 0
|
|
value = ''
|
|
preFix = '<Val>'
|
|
postFix = '</Val>'
|
|
|
|
with open(file_path) as fp:
|
|
for i, line in enumerate(fp):
|
|
if '<Dimsize>' in line:
|
|
lens.append(line[line.find('<Dimsize>')+len('<Dimsize>'):line.rfind('</Dimsize>')])
|
|
|
|
elif preFix in line and state == 0:
|
|
state = 1
|
|
value = value + line
|
|
if postFix in line:
|
|
state = 0
|
|
values.append(value)
|
|
value = ''
|
|
elif state == 1:
|
|
value = value + line
|
|
if postFix in line:
|
|
state = 0
|
|
values.append(value)
|
|
value = ''
|
|
|
|
arr = []
|
|
k = 0
|
|
for i in range(int(lens[0])):
|
|
arr.append([])
|
|
for j in range(int(lens[1])):
|
|
value = values[k]
|
|
arr[i].append(value[value.find(preFix)+len(preFix):value.rfind(postFix)])
|
|
k += 1
|
|
|
|
# for value in values:
|
|
# print(value[value.find(preFix)+len(preFix):value.rfind(postFix)])
|
|
# zip(*arr)
|
|
|
|
invArr = [['0' for x in range(int(lens[0]))] for y in range(int(lens[1]))]
|
|
|
|
for j in range(int(lens[0])):
|
|
for i in range(int(lens[1])):
|
|
invArr[i][j] = arr [j][i]
|
|
|
|
df = pd.DataFrame(invArr).T
|
|
df.to_excel(excel_writer = file_path + '.xlsx', index=False, header=False)
|