import xlrd,xlwt
class read_excel():
def read(self,path,index=0):
book=xlrd.open_workbook(path)
sheet=book.sheets()[index]
return sheet
def get_data_dir():
if Judge[-3] in desired_fulloads:
dir2 = {}
for desired_fulload in desired_fulloads:
if desired_fulload in Judge:
dir3 = {}
current_fulload = desired_fulload
for Order in Desired_Orders:
for i in range(14, a.nrows):
if a.cell(i, 0).value == Order:
desired_row = i
desired_value = a.cell(desired_row, 1).value
dir3[Order] = desired_value
dir2[current_fulload] = dir3
write_data_to_excel(dir2,delta_col)
def write_data_to_excel(dir2,delta_col):
for fulload, vlue in dir2.items():
for k in range(0, 6):
if desired_fulloads[k] == fulload:
row = -(k - 6)
for order, value in vlue.items():
print(current_direction, fulload, order, value)
for m in range(0, 5):
if Desired_Orders[m] == order:
col = m + delta_col
sheet1.write(row, col, value)
def check_direction(Judge):
if 'CCW.hdf' in Judge:
current_direction = 'CCW'
elif 'CW.hdf'in Judge or 'CW1.hdf' in Judge:#爲了這個我要瘋
current_direction = 'CW'
else:
current_direction = 'CCW'
return current_direction
enter_path=input('請輸入文件所在位置: ')
file_number=input('請輸入文件的數量: ')
book = xlwt.Workbook(encoding='utf-8')
sheet1 = book.add_sheet('sheet1')
style = xlwt.XFStyle()
sheet1.write(0,0,'CCW')
sheet1.write(0,6,'CW')
Desired_Orders=[8,12,16,23,25]
desired_fulloads = ['0%', '20%', '40%', '60%', '80%', '100%']
for i in range(0,6):
a=desired_fulloads[-i-1]+' load'
sheet1.write(i+1,0,a)
sheet1.write(i+1,6,a)
for j in range(0,5):
sheet1.write(0,j+1,Desired_Orders[j])
sheet1.write(0,j+7,Desired_Orders[j])
for i in range(1,int(file_number)+1):
path=enter_path+'/torque working point.'+str(i)+'.xlsx'
a=read_excel().read(path)
title=a.cell(3,1).value
Judge=title.split("_")
current_direction=check_direction(Judge)
if current_direction == 'CCW':
delta_col=1
get_data_dir()
if current_direction == 'CW':
delta_col=7
get_data_dir()
try:
book.save('D:\Structure born noise(radial direction).xls')
except PermissionError:
a = input("輸入一個不同的序號")
path = 'D:/Structure born noise(radial direction)' + str(a) + '.xls'
book.save(path)