How to Remove Formula in Excel using Python

This compact guide outlines the process of how to remove formula in Excel using Python. It has the environment settings, a list of steps, and a runnable sample code demonstrating how to delete formula in Excel using Python. You will also learn the command to delete all the formulas in a worksheet with a single API call.

Steps to Remove a Formula in Excel using Python

  1. Set the environment to use Aspose.Cells for Python via Java to remove formula
  2. Load the target workbook with a formula
  3. Access the formula cell and save its value in a temp variable
  4. Using the cell reference set the formula to an empty string
  5. Set the temp value back to the formula cell
  6. Save the resultant workbook with data only

These steps detail the procedure for how to remove a formula in Excel using Python. Simple logic is used where the value from the formula cell is saved in a temporary variable and the formula is set to an empty string. Afterward, the stored value is set back to the cell where the formula was present and the output workbook is saved on the disk.

Code to Delete Formula in Excel using Python

This code snippet demonstrates the task to clear formula in Excel using Python. It removes a formula from a single cell only however, if you want to clear formulas but keep values from all the cells in a worksheet, you may use getCells().removeFormulas() from the worksheet class. In this way, if you iterate through all the worksheets, all the cells in the complete workbook can be removed.

This article has taught us how to remove formula in Excel but keep data using Python. If you want to learn the process of copying a worksheet to another workbook, refer to the article on how to copy worksheet to another workbook in Python.

 English