SpreadJS9 定义自定义公式时可否从公式中获取Spread对象或Sheet对象?请各位大佬解答
window.onload = function () {
var spread2 = new GcSpread.Sheets.Spread(document.getElementById('ss'), {sheetCount:1 });
var spread1 = new GcSpread.Sheets.Spread(document.getElementById('ss1'),{sheetCount:1 });
$.wijmo.wijspread.Calc.Functions.defineGlobalCustomFunction("SUMBD", function(args, context){
var sheetName = context.source.getName();
var row = context.row;
var col = context.col;
var sheetInx = spread2.getSheetIndex(sheetName);
var sheet = spread2.getSheet(sheetInx);
var rowLevel = sheet.rowRangeGroup.getLevel(row);
if(rowLevel<0){
var i = 1;
var sum = sheet.getValue(row,col);
while(sheet.rowRangeGroup.getLevel(row+i) == rowLevel+1){
sum = sum + sheet.getValue(row+i);
i++;
}
return i;
}else{
return 0;
}
},{
override:true,
isContextSensitive: function(){return true;},
isVolatile: function(){return true;}
}
);
var sheet1 = spread1.getActiveSheet();
var sheet2 = spread2.getActiveSheet();
//设置值
sheet2.setValue(2,0,1);
sheet2.setValue(3,0,1);
sheet2.setValue(4,0,1);
sheet2.setValue(5,0,1);
//sheet2.setValue(6,0,1);
sheet1.setValue(2,0,2);
sheet1.setValue(3,0,2);
sheet1.setValue(4,0,2);
sheet1.setValue(5,0,2);
//设置分组
sheet2.rowRangeGroup.direction =$.wijmo.wijspread.RangeGroupDirection.Backward;//Forward
sheet1.rowRangeGroup.direction =$.wijmo.wijspread.RangeGroupDirection.Backward;//Forward
sheet2.rowRangeGroup.group(2, 4);
sheet1.rowRangeGroup.group(2, 4);
sheet2.setFormula(1,0,'SUMBD()');
sheet1.setFormula(1,0,'SUMBD()');
};
|
|