好像不能传附件,我把整个demo的js贴一下- //自定义 可见区域的sumif 函数
- var sheet ;
- function SumIfVisibleFunction() {
- this.name = "SUMIFVISIBLE";
- this.maxArgs = 1;
- this.minArgs = 1;
- }
- SumIfVisibleFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
- SumIfVisibleFunction.prototype.acceptsReference = function (index) {
- return index === 0 ;
- }
- SumIfVisibleFunction.prototype.evaluate = function (range) {
- console.log("---计算函数")
- let col = range.getColumn() , row = range.getRow() , rowCount = range.getRowCount() , colCount = range.getColumnCount();
- var sum = 0;
- for(let i = 0 ; i < rowCount ; i++){
- if(sheet.getRowVisible( row + i)){
- let value = sheet.getValue( row + i , col);
- let type = sheet.getValue( row + i , 0);
- if(!value || type === 'a'){
- continue;
- }
- if(!isNaN(parseInt(value))) {
- sum += parseInt(value);
- }else{
- return '#VALUE'
- }
- }
- }
- return sum;
- }
- var sumifvisible = new SumIfVisibleFunction();
-
-
-
- window.onload = function () {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
- initSpread(spread);
- };
-
-
-
-
-
- function initSpread(spread) {
- sheet = spread.getSheet(0);
-
- let data = [
- { type : 'a' , value : 1 },
- { type : 'a' , value : 1 },
- { type : 'b' , value : 1 },
- { type : 'b' , value : 1 },
- { type : 'c' , value : 1 },
- { type : 'c' , value : 1 },
- { type : 'c' , value : 1 },
- ]
-
- sheet.bindColumns([
- { name: 'type' } , { name: 'value' } ,
- ]);
-
- sheet.setDataSource(data);
-
- sheet.addCustomFunction(sumifvisible);
- sheet.setFormula(0 , 1 , '=sumifvisible(Sheet1!B:B)' , GC.Spread.Sheets.SheetArea.colHeader);
-
-
- var basedFilterRange = new GC.Spread.Sheets.Range(-1,-1,-1,-1);
- var rowFilter = new GC.Spread.Sheets.Filter.HideRowFilter(basedFilterRange);
- sheet.rowFilter(rowFilter);
- rowFilter.filterButtonVisible(false);
- rowFilter.filterButtonVisible(0,true);
-
-
- sheet.bind(GC.Spread.Sheets.Events.RangeSorted, function (e, info) {
- sheet.recalcAll();
- });
- sheet.bind(GC.Spread.Sheets.Events.RangeFiltered, function (e, info) {
- sheet.recalcAll();
- });
- };
-
复制代码 html就是咱们实例的代码 |