Fail to calculate CELL("filename")

Upon calling calculateFormula on a workbook that has a cell with =CELL("filename", B2) formula fails to calculate the cell.

Screenshot 2025-09-26 at 10.20.57 AM.jpg (146.0 KB)

Excel file to repro:
image.png (20.7 KB)

@yoohee

The issue with the =CELL("filename", B2) formula not calculating in your workbook may be related to how Aspose.Cells handles certain Excel functions. The CELL function can sometimes return unexpected results or fail to calculate if the workbook is not properly initialized or if the cell references are not valid.

To troubleshoot this, ensure that:

  1. The workbook is fully loaded and all necessary data is present before calling CalculateFormula.
  2. The cell reference (B2 in this case) is valid and contains the expected data.

Here’s a simple code snippet to ensure the workbook is loaded and formulas are calculated:

// Load the workbook
Workbook workbook = new Workbook("path_to_your_file.xlsx");

// Ensure all formulas are calculated
workbook.CalculateFormula();

// Access the cell with the formula
Cell cell = workbook.Worksheets[0].Cells["A1"]; // Change "A1" to the cell with your formula
string filename = cell.StringValue; // This should now contain the filename

If the problem persists, consider reviewing the Aspose.Cells documentation for any specific notes on the CELL function or related formula calculations.

@yoohee,

The CELL formula/function is supported in newer versions. We recommend you to kindly try using our latest version: Aspose.Cells for Java 25.9.

If you still find the issue, kindly do share your sample (runnable) code and template Excel file to reproduce the issue on our end, we will check it soon.

@amjad.sahi

I tried the same file on 25.9 and I can still reproduce the issue.

Code snippet:

        try (FileInputStream inputStream = new FileInputStream(inputFilePath);
             FileOutputStream outputStream = new FileOutputStream(outputFilePath)) {
            
            // Load the Excel workbook
            Workbook workbook = new Workbook(inputStream);
            
            workbook.calculateFormula();
            
            // Create PDF save options
            PdfSaveOptions saveOptions = new PdfSaveOptions();
            saveOptions.setOnePagePerSheet(true);
            
            // Save as PDF
            workbook.save(outputStream, saveOptions);
            
        } catch (Exception e) {
            throw new IOException("Failed to convert Excel to PDF: " + e.getMessage(), e);
        }

Excel File:
Book2.xlsx.zip (7.4 KB)

@yoohee,

Thanks for the template Excel file.

I reproduced the issue as you mentioned by using your template Excel file and sample code snippet. I found Aspose.Cells formula calculation engine failed to calculate CELL(“filename”,…) formula/function.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46509

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@yoohee

For CELL(“filename”, reference) function, it’s purpose is to get the file name of current workbook. However, when instantiating the workbook from stream, we cannot know the file name from which the stream is built. To make this function works like what you get in ms excel, please specify the file name with the correct value for the workbook:

...
workbook.setFileName(inputFilePath);
workbook.calculateFormula();
...

Hi @johnson.shi,

Yes, that did the trick. Thank you!

@yoohee
You are welcome!
We are glad to hear that your issue was fixed with suggested codes.