[Bug 68305] Invalid sheetIndex Error in formulaEvaluator.evaluate(cell) for Cell Formula with Escaped Apostrophe in Sheet Name

[email protected] Tue, 28 Jul 2026 10:00:05 +0000
Newsgroups gmane.comp.jakarta.poi.devel
Message-ID <[email protected]/bugzilla/>
https://bz.apache.org/bugzilla/show_bug.cgi?id=3D68305

[email protected] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #4 from [email protected] ---
I could reproduce this with the following code


import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;

class PoiApostropheFormulaTest {

        @Test
        void
evaluateAll_shouldNotThrow_whenNameFormulaReferencesSheetWithApostrophe()
throws IOException {
                try (Workbook workbook =3D
createWorkbookWithApostropheNameFormula()) {
                        FormulaEvaluator evaluator =3D
workbook.getCreationHelper().createFormulaEvaluator();

                        // This call throws IllegalArgumentException: Inval=
id
sheetIndex
                        evaluator.evaluateAll();=20
                }
        }

        private static Workbook createWorkbookWithApostropheNameFormula() {
                Workbook workbook =3D new XSSFWorkbook();

                // Sheet name containing an apostrophe
                Sheet dataSheet =3D workbook.createSheet("L'embrace");
                dataSheet.createRow(0).createCell(0).setCellValue(42);

                // Defined name pointing at the apostrophe sheet, correctly
escaped per Excel syntax
                Name name =3D workbook.createName();
                name.setNameName("myLocalName");
                name.setRefersToFormula("'L''embrace'!$A$1");
                name.setSheetIndex(workbook.getSheetIndex(dataSheet));

=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
dataSheet.getRow(0).createCell(1).setCellFormula("myLocalName");

                return workbook;
        }
}

--=20
You are receiving this mail because:
You are the assignee for the bug.=