Receiving Cannot get a NUMERIC value from a BOOLEAN cell when exporting XML map

I have a workbook with an XML mapping defined (I am using POI 4.1.2).

A mapped cell contains a formula which evaluates to boolean: =AND(B70="";B71=""; B50="No")

I try to export the XML mapping with the following code:

// First ensure that all formulas are evaluated
// Export XML map
String file = "path/to/file.xml";
XSSFWorkbook xssfWorkbook = (XSSFWorkbook) wb;
XSSFMap xssfMap = xssfWorkbook.getCustomXMLMappings().stream().findFirst().get();
XSSFExportToXml exporter = new XSSFExportToXml(xssfMap);
OutputStream out = new FileOutputStream(file);
exporter.exportToXML(out, false);

The last line results to the following exception:

java.lang.IllegalStateException: Cannot get a NUMERIC value from a BOOLEAN cell at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch( at org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue( at at at org.apache.poi.xssf.extractor.XSSFExportToXml.mapCellOnNode(

When i look into XSSFExportToXml.mapCellOnNode(XSSFCell, Node) I see the following code:

private void mapCellOnNode(XSSFCell cell, Node node) {

    String value ="";
    switch (cell.getCellType()) {

    case STRING: value = cell.getStringCellValue(); break;
    case BOOLEAN: value += cell.getBooleanCellValue(); break;
    case ERROR: value = cell.getErrorCellString();  break;
    case FORMULA:
       if (cell.getCachedFormulaResultType() == CellType.STRING) { // cell.getCachedFormulaResultType() returns BOOLEAN
           value = cell.getStringCellValue();
       } else {
           if (DateUtil.isCellDateFormatted(cell)) { // Results in Exception
              value = getFormattedDate(cell);
           } else {
              value += cell.getNumericCellValue();
    case NUMERIC: 
         if (DateUtil.isCellDateFormatted(cell)) {
              value = getFormattedDate(cell);
          } else {
             value += cell.getRawValue();


    if (node instanceof Element) {
        Element currentElement = (Element) node;
    } else {

From my understanding there is a bug in mapCellOnNode. Inside case FORMULA the expression cell.getCachedFormulaResultType() returns BOOLEAN but inside this block only STRING and NUMERIC are considered. This leads to executing DateUtil.isCellDateFormatted(cell) which results in an Exception.

So my question is: am I right? Is it a bug? Or am I missing something?


I have applied a fix to the POI code – see – this will be included in next POI release

Source: stackoverflow