When we have the formula
- =IF(A1=""; “Empty”; “Not empty”)
This is evaluated as in Excel if we
- Have a value
- Explicitly set value to emty string ““
It is not evaluated as in Excel if we
- clear the cell in Excel
- clear the cell by code: inputs.getCells().getCell(“A1”).clearContent();
Test code:
import java.io.FileInputStream;
import java.io.IOException;
import com.aspose.cells.AsposeLicenseException;
import com.aspose.cells.License;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class EmptyIfTest {
public static void main(String[] args) throws IOException, AsposeLicenseException {
License lic = new License();
lic.setLicense(new FileInputStream(“lib/Aspose.Cells.lic”));
Workbook workbook = new Workbook();
workbook.open(“Excel/emptyiftest.xls”);
Worksheet inputs = workbook.getWorksheets().getSheet(“Inputs”);
inputs.getCells().getCell(“A1”).clearContent();
inputs.getCells().getCell(“A3”).setValue(””);
workbook.calculateFormula();
System.out.println("A1: "+inputs.getCells().getCell(“A1”).getValue());
System.out.println("B1: "+inputs.getCells().getCell(“B1”).getValue());
System.out.println("B1 formula: " + inputs.getCells().getCell(“B1”).getFormula());
System.out.println("A2: "+inputs.getCells().getCell(“A2”).getValue());
System.out.println("B2: "+inputs.getCells().getCell(“B2”).getValue());
System.out.println("B2 formula: " + inputs.getCells().getCell(“B2”).getFormula());
System.out.println("A3: "+inputs.getCells().getCell(“A3”).getValue());
System.out.println("B3: "+inputs.getCells().getCell(“B3”).getValue());
System.out.println("B3 formula: " + inputs.getCells().getCell(“B3”).getFormula());
workbook.save(“Excel/Result.xls”);
}
}
If you compare the output with the Result.xls file you will find the B1 cell evaluated to “Empty” in the excel spreadsheet but to “Not empty” in the console output.