作成日: 2022/04/18 最終更新日: 2024/10/17
文書種別
不具合
状況
修正済み
詳細
COUNTIFの検索条件が、ブランク(null)、0、1の場合、SpreadJSとExcelで以下のように結果が異なります。
- 検索条件がブランク(null)の場合、SpreadJSは0とFALSEを検索しますが、Excelは0のみを検索します。
- 検索条件が0の場合、SpreadJSは0とFALSEを検索しますが、Excelは0のみを検索します。
- 検索条件が1の場合、SpreadJSは1とTRUEを検索しますが、Excelは1のみを検索します。
回避方法
SpreadJS (Ver.15.1.4)以降のバージョンでは、Excelの互換モード(ExcelCompatibleCalcMode)を有効にして、Excelと同じ結果にすることが可能です。
GC.Spread.CalcEngine.ExcelCompatibleCalcMode = true;
Ver.15.1.4より前のバージョンでは、以下のようにCOUNTIFのカスタム関数を作成してワークブックに追加して回避可能です。
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var sheet = spread.getActiveSheet();
function COUNTIFFunction() {
this.name = "COUNTIF";
this.maxArgs = 2;
this.minArgs = 2;
}
COUNTIFFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
COUNTIFFunction.prototype.acceptsReference = function (args) {
return (args===0);
}
COUNTIFFunction.prototype.evaluate = function () {
var values = arguments[0].toArray();
var search = arguments[1];
const result = values.filter((value) => {
if (search === null) {
return value === 0;
}
else {
return value === search;
}
});
return result.length;
}
countif = new COUNTIFFunction();
spread.addCustomFunction(countif);