Subtotal函数对隐藏的列区域无效。这个在excel中也是一样的效果。SpreadJs有一个ColumnChanged事件,可以获取改变的列,当判断当前改变的列的sheetArea是colHeader,且旧值为true,新值为false。可以判断出该列被隐藏了。此时可以重新计算。
- sheet.setFormula(8, 0, '=sum(B9:G9)')
- sheet.setValue(8, 1, 1)
- sheet.setValue(8, 2, 2)
- sheet.setValue(8, 3, 3)
- sheet.setValue(8, 4, 4)
- sheet.setValue(8, 5, 5)
- sheet.bind(GC.Spread.Sheets.Events.ColumnChanged, function (e, info) {
- const {newValue, sheetArea, oldValue, col} = info;
- if (sheetArea == 3 && newValue == false && oldValue == true) { //隐藏列
- sheet.setFormula(8, 0, null)
- let sum = 0;
- for (let i = 1; i < 6; i++) {
- if (i !== col) {
- sum += sheet.getValue(8, i);
- }
- }
- sheet.setValue(8, 0, sum);
- }
- });
复制代码
|