请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册

QQ登录

只需一步,快速开始

Dtttax

银牌会员

274

主题

680

帖子

2184

积分

银牌会员

积分
2184
Dtttax
银牌会员   /  发表于:2018-12-6 18:21  /   查看:6529  /  回复:14
1、比如加进来有单元格的公式用到另外的sheet,这时候sheet还没建,,sheet没建好的时候公式无效,想把这行隐藏,公式有效了就显示这行。2、 公式计算的时候如果取每个单元格整数计算,能否重写这个公式,或者自定义公式



14 个回复

倒序浏览
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-12-7 11:48:17
沙发
您好,

1、隐藏行与列可以实现,请参考setRowVisible和setColumnVisible 的API:

http://help.grapecity.com/spread ... ~setRowVisible.html

http://help.grapecity.com/spread ... tColumnVisible.html

2、自定义公式可以实现,请参考学习指南:

https://demo.grapecity.com.cn/Sp ... mos/customFunctions
回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2018-12-7 18:34:08
板凳
另外可以直接重写公式么,比如求和sum 取每个单元格的整数部分相加
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2018-12-10 09:25:11
地板
Dtttax 发表于 2018-12-7 18:34
另外可以直接重写公式么,比如求和sum 取每个单元格的整数部分相加

您好,可以直接重写,只要您自定义时设置的公式名称与要重写的公式名称相同即可。

示例代码:

  1. window.onload = function () {
  2.             var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
  3.             initSpread(spread);
  4.         };

  5.         function initSpread(spread) {
  6.             var sheet = spread.getSheet(0);

  7.             sheet.setValue(1, 1, 'Press \'Add a Custom Function\' button');
  8.             sheet.setColumnWidth(1, 225);
  9.             sheet.setColumnWidth(2, 100);
  10.             function FactorialFunction() {
  11.                 this.name = "SUM";
  12.                 this.maxArgs = 1;
  13.                 this.minArgs = 1;
  14.             }
  15.             FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
  16.             FactorialFunction.prototype.evaluate = function (arg) {
  17.                 var result = 1;
  18.                 if (arguments.length === 1 && !isNaN(parseInt(arg))) {
  19.                     for (var i = 1; i <= arg; i++) {
  20.                         result = i * result;
  21.                     }
  22.                     return result;
  23.                 }
  24.                 return "#VALUE!";
  25.             };
  26.             var factorial = new FactorialFunction();

  27.             document.getElementById("addCustomFunction").addEventListener('click',function() {
  28.                 sheet.setValue(3, 1, 'Formula');
  29.                 sheet.setValue(3, 2, '=SUM(5)');
  30.                 sheet.setValue(4, 1, 'Result');
  31.                 sheet.addCustomFunction(factorial);
  32.                 sheet.setFormula(4, 2, "=SUM(5)");
  33.             });

  34.             document.getElementById("removeCustomFunction").addEventListener('click',function() {
  35.                 sheet.removeCustomFunction("SUM");
  36.             });
  37.         };
复制代码

回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2019-3-5 11:01:53
5#
我们是每个单元格通过formatter四舍五入,目前公式计算是取的value,这样结果看起来很怪,比如:0.3 四舍五入是0,0.4四舍五入是0,sum算出来0.3+0.4四舍五入是1,看起来就是0+0=1,我们需要的是0+0=0
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-3-5 13:35:15
6#
您好,其实formatter是可以自定义的,您可以参考一下这个示例:

https://demo.grapecity.com.cn/Sp ... mos/customFormatter
回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2019-3-5 13:42:48
7#
我们想要的是每个单元格四舍五入后再参与计算,但是公式计算是拿的value,这个value是小数,有没有办法把value四舍五入后再计算呢
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-3-5 18:38:03
8#
您好,抱歉理解错了您的意思,您要改变单元格的value,

如果绑定了数据源,实际上直接对数据源的value进行四舍五入操作效率是最高的。

或者采用自定义函数,自己在函数中对参数进行四舍五入的操作。

原生函数在不改变函数表达式的情况下没法自动四舍五入。
回复 使用道具 举报
Dtttax
银牌会员   /  发表于:2019-3-6 09:02:45
9#
数据源还是要保留小数位的,在自定义函数中怎么对源数据四舍五入呢
回复 使用道具 举报
KevinChen讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2019-3-6 11:17:25
10#
实际上,自定义函数里就是在evaluate方法里,获取到的的参数就是单元格的值,

这时您可以完全自定义函数逻辑,在函数中进行自己需要的任何计算。

但自定义函数不支持导出到Excel中,这点需要提醒您注意。

具体自定义函数的用法,请参考学习指南:

https://demo.grapecity.com.cn/Sp ... mos/customFunctions
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部