Nov-08-2022, 05:20 AM

i have problem-related with excel, it seems like convert from txt to excel the data is a string not float. Is there any solution to convert it to float?

I have a text file name result.txt as below

Does anyone know how to change it?

please refer to the excel picture, the column has a green mark which is an error, I want to show it as float not string

I have a text file name result.txt as below

datettime Tput 20221018.165317.401555 0.000545 20221018.165327.401723 0.001422 20221018.165337.401893 0.001283 20221018.165347.402060 0.000476excel.py will convert the txt file to excel

import openpyxl, string from openpyxl.utils import get_column_letter from openpyxl.styles import Font def excelconvertMAC(result): #f = open(r'C:\MAC_add_Submission\data_out.txt', 'r+') # open text f = open(result, 'r+') # open text #########if load excel file ######################## # excel=openpyxl.load_workbook(r'D:\\test\\test.xlsx') #open excel # excel=openpyxl.load_workbook(r'D:\\test\\test.xlsx') #open excel excel = openpyxl.Workbook() sheet = excel.worksheets line = f.readline(); # read text while line: list123 = [] #list123 = line.split(sep=' ') # convert, list123 = line.split() # convert, #print(type(list123[1])) #print(list123) for i in range(0, len(list123)): # remove space list123[i] = list123[i].strip('\n') sheet[0].append(list123) # write into excel #print(sheet[0]) # sheet[0].column_dimensions.width = 20 #adjust the column width column = 1 while column < 6: i = get_column_letter(column) #print(i) sheet[0].column_dimensions[i].width = 25 column += 1 sheet[0]['A1'].font = Font(size = 14, bold = True) sheet[0]['B1'].font = Font(size = 14, bold = True line = f.readline() # read next line excel.save('result.xlsx') #resultfilename=input("please enter your report txt file name: ") resultfilename="result.txt" excelconvertMAC(resultfilename)After converting to excel, open excel you will see that the second columns seem like strings not float.

Does anyone know how to change it?

please refer to the excel picture, the column has a green mark which is an error, I want to show it as float not string