为什么逻辑 IFS() 函数一直以小写形式呈现?

Why does the logical IFS() function keep getting rendered in lowercase?

我正在从 java 代码动态生成 XLSX 文件,并设置公式。除了 IFS() 函数外,所有工作都很好,但似乎总是使用小写 "ifs()" 呈现,因此在打开结果文件时,libreoffice 无法将其识别为函数。所有其他公式,例如普通的旧 "IF" 工作正常

我试过调试 POI ooxml 源代码,最后我能说的是单元格被正确设置为大写。我已经尝试更新到最新版本,预先格式化单元格内容......到目前为止没有运气。此代码在 poi 4.0.1 上运行,我正在使用 libreoffice 6.1.3.2 打开文件(以防这可能是 libreoffice 问题?)。我无权访问 EXCEL 2016+ 来检查它如何处理生成的文件。

public void testIFS(){
    try {
        String IFSformula = "IFS(1,\"yes\",0,\"no\")";
        String IFformula = "IF(1,\"yes\",\"no\")";
        String outputFileName = "IFStest.xlsx";
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet poiSheet = workbook.createSheet("ifstest");
        XSSFRow row = poiSheet.createRow(0);
        XSSFCell cell0 = row.createCell(0);
        cell0.setCellFormula(IFSformula);
        XSSFCell cell1 = row.createCell(1);
        cell1.setCellFormula(IFformula);
        workbook.write(new FileOutputStream(outputFileName));
    } catch (IOException ex) {
        Logger.getLogger(IFSTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

现在,单元格 0 以 =ifs(1,"yes",0,"no") 结束 - 这是错误的(结果是#NAME),但单元格 1 工作正常并且具有单元格公式 =IF(1,"yes","no")(结果 "yes")。如果我手动将 "ifs" 更改为 "IFS",则公式工作正常并且还显示 "yes".

最新LibreOffice Calc支持IFS。但是,如果它保存 *.xlsx 文件,那么它会使用 _xlfn 前缀存储 IFS 公式。通常 _xlfn 前缀表示 The Excel workbook contains a function that is not supported in the version of Excel that you are currently running.. So seems that LibreOffice Calc tries saving in Excel 2016 compatible mode. The IFS function 仅从 Office 365 向上。而且由于它使用该前缀存储,因此在阅读 *.xlsx 时似乎也期望该前缀。

甚至 Office 365 Excel_xlfn.IFS 存储到 *.xlsx 文件中,而不仅仅是 IFS(今天测试,2019 年 1 月 21 日)。所以 LibreOffice Calc 期望该前缀也是正确的。

以下对我有用,使用 apache poi 4.0.1 创建 *.xlsx 并使用 LibreOffice Calc(版本:6.0.7.3 构建 ID:1:6.0.7-0ubuntu0。 18.04.2) 以及使用 Office 365 打开 *.xlsx then.

import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

class TestIFS {

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

  try (XSSFWorkbook workbook = new XSSFWorkbook(); FileOutputStream out = new FileOutputStream("TestIFS.xlsx")) { 
   String formulaIFS = "_xlfn.IFS(1=0,\"first\",0=0,\"second\")";
   String formulaIF = "IF(1=0,\"yes\",\"no\")";
   Sheet sheet = workbook.createSheet("IFStest");
   Row row = sheet.createRow(0);
   Cell cell = row.createCell(0);
   cell.setCellFormula(formulaIFS);
   cell = row.createCell(1);
   cell.setCellFormula(formulaIF);
   workbook.write(out); 
  }
 }
}