Remove Excel Formulas but Keep Values in Java

Import JAR Dependency (2 Method)

1# Download the free library and unzip it, then add the Spire.Xls.jar file to your project as dependency.


Sample Code

import com.spire.xls.*;

public class RemoveFormulas {
public static void main(String[] args) throws Exception {

//Create a workbook.
Workbook workbook = new Workbook();

//Load the file from disk.

//Loop through worksheets.
for (Worksheet sheet : (Iterable<Worksheet>) workbook.getWorksheets())
//Loop through cells.
for (CellRange cell : (Iterable<CellRange>) sheet.getRange())
//If the cell contains formula, get the formula value, clear cell content, and then fill the formula value into the cell.
if (cell.hasFormula())
Object value = cell.getFormulaValue();

//Save to file
workbook.saveToFile("removeFormulasButKeepValues.xlsx", ExcelVersion.Version2013);



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store