0

I have an Excel file with data in column A. I want to loop through each cell and select the row that that i first come across that has a formula.

This is my code:

import openpyxl 
wb=openpyxl.load_workbook(path1)
sheet = wb['Sheet1']

names=sheet['A']

for cellObj in names:
    val = str(cellObj.value)
    if val[0] == "=":
        #select the row from column A to Z and make it's values equal to itself (like doing a copy/pasteSpecial values in excel to remove the formula)

I guess i can append the row in an empty list then make it equal to the row again, but how do i even do that?

Thanks!

1
  • You check for the cell.data_type == "f" Commented Feb 14, 2022 at 15:16

1 Answer 1

1

Basically, you just wanted to remove the formula and leave the actual data itself? If you want this for the whole file then add data_only=True. I also suggest saving the workbook in a different filename or create a copy of original excel file.

import openpyxl 
wb = openpyxl.load_workbook(path1, data_only=True) 
wb.save(save_path)
wb.close()
Sign up to request clarification or add additional context in comments.

1 Comment

I am only trying to remove the formula from the FIRST row that contains a formula. I have many other formulas elsewhere i don't want to remove.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.