CODE IN PYTHON PLEASE The objective is to create a code in Python that can extract the columns highlighted in blue (Column T and AB3) and output them to a .txt file. The code should be able to generate the text file with the columns that are highlighted in blue and store them on a separate folder. Below shows how the Test.xlsm file looks like as well as how the text file should look like when the code extracts and outputs it. Google drive to access Test.xlsm file: https://drive.google.com/drive/folders/16utzb5_h7yMCN8_13E_JqasfcpykZOYr?usp=sharing What my code outputs is shown in the picture (O1.png) What I would like for my code to output is the columns next to each other (Right Example.png) The current code is able to output Columns T and AB3 but I am not able to output them next to each other as shown above. We would also like for the code to be capable of storing the text file to a separate folder. Below is the code I have been working on. #package to read xlsm file import openpyxl #give full path to excel file here path = "Test.xlsm" #loading the excel sheet wb_obj = openpyxl.load_workbook(path) #lading the required sheet by name from excel sheet_obj = wb_obj["Correct-L"] #opening text file to write data. f = open("Correct_l.txt","w") #getting max number of rows sheet has, so we can loop through all rows num_row = sheet_obj.max_row #writing the first line to text file f.writelines("Band Group Number Time\n") #for loop to get data from first blue column #and saving every value that is not None to text file for i in range(3,num_row+1): cell_obj = sheet_obj.cell(row=i, column=20) if str(cell_obj.value) != "None": f.writelines(str(cell_obj.value)+"\n") f.writelines("Band Group Number Time\n") #for loop to get data from second blue column #and saving every value that is not None to text file for i in range(3,num_row+1): cell_obj = sheet_obj.cell(row=i, column=28) if str(cell_obj.value) != "None": f.writelines(str(cell_obj.value) + "\n")
CODE IN PYTHON PLEASE
The objective is to create a code in Python that can extract the columns highlighted in blue (Column T and AB3) and output them to a .txt file. The code should be able to generate the text file with the columns that are highlighted in blue and store them on a separate folder. Below shows how the Test.xlsm file looks like as well as how the text file should look like when the code extracts and outputs it.
Google drive to access Test.xlsm file: https://drive.google.com/drive/folders/16utzb5_h7yMCN8_13E_JqasfcpykZOYr?usp=sharing
What my code outputs is shown in the picture (O1.png)
What I would like for my code to output is the columns next to each other (Right Example.png)
The current code is able to output Columns T and AB3 but I am not able to output them next to each other as shown above. We would also like for the code to be capable of storing the text file to a separate folder. Below is the code I have been working on.
#package to read xlsm file import openpyxl #give full path to excel file here path = "Test.xlsm" #loading the excel sheet wb_obj = openpyxl.load_workbook(path) #lading the required sheet by name from excel sheet_obj = wb_obj["Correct-L"] #opening text file to write data. f = open("Correct_l.txt","w") #getting max number of rows sheet has, so we can loop through all rows num_row = sheet_obj.max_row #writing the first line to text file f.writelines("Band Group Number Time\n") #for loop to get data from first blue column #and saving every value that is not None to text file for i in range(3,num_row+1): cell_obj = sheet_obj.cell(row=i, column=20) if str(cell_obj.value) != "None": f.writelines(str(cell_obj.value)+"\n") f.writelines("Band Group Number Time\n") #for loop to get data from second blue column #and saving every value that is not None to text file for i in range(3,num_row+1): cell_obj = sheet_obj.cell(row=i, column=28) if str(cell_obj.value) != "None": f.writelines(str(cell_obj.value) + "\n")
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images