Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

Is there any function which can delete specific string in each row in the file by using python

I am new to python and try to use write the excel data into a text file with a specific format. But somehow I am facing a problem with duplication of data.

f = open("test1.txt", "a+")                                                                   # Text 
file create here

f5 = []
i = []
j = []
flag = False
for sheet in allSheetNames:
     currentSheet = theFile[sheet]


     for row in range(2, currentSheet.max_row + 1):                                          
    
    
        for column in "ABCDEF":                                                              
            cell_name = "{}{}".format(column, row)
        
        
            if currentSheet[cell_name].value == None: 
                j = I
                flag = True
            else:
                f.write("{}".format(currentSheet[cell_name].value))
                i = cell_name
                flag = True
            

                #if flag == True:
                   #if j != I:
                      # print("{}".format(currentSheet[i].value))
             
                     #flag = False
    
f.close()                                                                                 
 exit()   

The committed part actually I am trying to compare the column number and similar column number is trying to avoid `enter code here duplication.

Here is the text file which actually I required as an output.
enter image description here
enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thank you, This is solved by using separate indexes first and elemental those indexes which are duplicate.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...