找回密码
 立即注册

QQ登录

只需一步,快速开始

许少雄

金牌服务用户

10

主题

18

帖子

70

积分

金牌服务用户

积分
70
许少雄
金牌服务用户   /  发表于:2024-9-26 14:49  /   查看:211  /  回复:2
1金币

function customFunctions10(GC) {
  function hideRowFunction() {
    this.typeName = "HIDEROW";
    this.name = "HIDEROW";
    this.maxArgs = 1;
    this.minArgs = 1;
    this.description = function () {
      return {
        description: "HIDESPECIFIEDROW",
      };
    };
  }

  // 继承内置 Function
  hideRowFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();

  // 根据逻辑,重写 evaluate
  hideRowFunction.prototype.evaluate = function (context, rowIndex) {
    // 获取当前 sheet
    var sheet = context.sheet;

    // 检查 rowIndex 是否为有效的数字
    if (typeof rowIndex !== "number" || rowIndex < 0 || rowIndex >= sheet.getRowCount()) {
      throw new Error("Invalid row index");
    }

    // 隐藏指定的行
    sheet.setRowVisible(rowIndex, false);
   
    // 返回隐藏行的提示
    return `Row ${rowIndex} is hidden`;
  };

  var hideRow = new hideRowFunction();

  // 全局注册自定义函数
  GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("HIDEROW", hideRow);
}


1727333324013.png

最佳答案

查看完整内容

您好,请参考以下代码实现: function hideRowFunction() { this.typeName = "HIDEROW"; this.name = "HIDEROW"; this.maxArgs = 1; this.minArgs = 1; this.description = function () { return { description: "HIDESPECIFIEDROW", }; }; } // 继承内置 Function hideRowFunction.prototype = new GC.Spread.CalcEngine.Functions.Function(); // 根据逻辑,重写 evaluate hideR ...

2 个回复

倒序浏览
最佳答案
最佳答案
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-9-26 14:49:46
来自 2#
您好,请参考以下代码实现:

function hideRowFunction() {
  this.typeName = "HIDEROW";
  this.name = "HIDEROW";
  this.maxArgs = 1;
  this.minArgs = 1;
  this.description = function () {
    return {
      description: "HIDESPECIFIEDROW",
    };
  };
}

// 继承内置 Function
hideRowFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();

// 根据逻辑,重写 evaluate
hideRowFunction.prototype.evaluate = function (context, rowIndex) {
  // 获取当前 sheet
  var sheet = context.source.getSheet();

  // 检查 rowIndex 是否为有效的数字
  if (
    typeof rowIndex !== "number" ||
    rowIndex < 0 ||
    rowIndex >= sheet.getRowCount()
  ) {
    throw new Error("Invalid row index");
  }

  // 隐藏指定的行
  sheet.setRowVisible(rowIndex, false);

  // 返回隐藏行的提示
  return `Row ${rowIndex} is hidden`;
};
hideRowFunction.prototype.isContextSensitive = function () {
  return true;
};
var hideRow = new hideRowFunction();

// 全局注册自定义函数
GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("HIDEROW", hideRow);
回复 使用道具 举报
Wilson.Zhang
超级版主   /  发表于:2024-9-29 09:57:30
3#
您好!由于您较长时间未回复,且从跟帖回复中了解到问题已得到有效解决方案,那就结贴了。如有问题,欢迎发新帖沟通。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部