找回密码
 立即注册

QQ登录

只需一步,快速开始

sssf

注册会员

1

主题

3

帖子

12

积分

注册会员

积分
12
  • 37

    金币

  • 1

    主题

  • 3

    帖子

最新发帖
sssf
注册会员   /  发表于:2024-3-21 15:07  /   查看:635  /  回复:7
本帖最后由 Richard.Huang 于 2024-4-3 17:47 编辑

产品:SpreadJS
版本:V16.2.6

  1. function EPMMemberProperty() {
  2.   this.maxArgs = 3;
  3.   this.minArgs = 1;
  4.   this.name = "EPMMemberProperty";
  5.   this.description = function () {
  6.     return {
  7.       description: "获取指定成员的指定属性值",
  8.       parameters: [
  9.         {
  10.           name: "连接名称",
  11.           repeatable: false,
  12.           optional: false,
  13.         },
  14.         {
  15.           name: "成员",
  16.           repeatable: false,
  17.           optional: false,
  18.         },
  19.         {
  20.           name: "属性",
  21.           repeatable: false,
  22.           optional: false,
  23.         },
  24.       ],
  25.     };
  26.   };
复制代码
上面是我设置一个自定公式函数
然后在使用时我只设置第二个参数,保存得到的是以下公式

参数的位置变成第一个,与设置的位置不匹配
怎么解决这个问题,或者是如何设置默认参数
image.png205232543.png
image.png977008361.png

7 个回复

倒序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2024-3-21 17:41:39
沙发
您好,
完整的自定义函数代码请提供下, 另外,您是否是在designer 插入函数 弹窗中自定义添加了该自定义函数?
建议直接提供一个复现demo,使我们可以通过此demo直接验证贴中描述,以便问题的进一步调研。
回复 使用道具 举报
sssf
注册会员   /  发表于:2024-3-21 19:12:14
板凳
本帖最后由 sssf 于 2024-3-21 19:31 编辑
Lynn.Dou 发表于 2024-3-21 17:41
您好,
完整的自定义函数代码请提供下, 另外,您是否是在designer 插入函数 弹窗中自定义添加了该自定义 ...

你好,下面就是完整的定义公式的代码:
  1. function       defindFunction() {
  2.         function customFontFamilyInFormatDialogTemplate(templateNode) {
  3.         
  4.           if (templateNode.bindingPath && templateNode.bindingPath === 'functionDesc.allFunction' && templateNode.items) {
  5.   
  6.             templateNode.items.unshift({ text: "获取成员属性", value: "EPMMemberProperty" })
  7.   
  8.             return;
  9.           }
  10.           let nodes = templateNode.content || templateNode.children;
  11.           if (nodes && nodes instanceof Array) {
  12.             nodes.forEach((subNode) => customFontFamilyInFormatDialogTemplate(subNode));
  13.           }
  14.         }
  15.         
  16.         var template = GC.Spread.Sheets.Designer.getTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate);
  17.         customFontFamilyInFormatDialogTemplate(template);
  18.         GC.Spread.Sheets.Designer.registerTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate, template);
  19.   
  20.         // 自定义公式一
  21.         function EPMMemberProperty() {
  22.           this.maxArgs = 3;
  23.           this.minArgs = 1;
  24.           this.name = 'EPMMemberProperty'
  25.           this.description = function () {
  26.             return (
  27.               {
  28.                 description: "获取指定成员的指定属性值",
  29.                 parameters: [
  30.                   {
  31.                     name: '连接名称',
  32.                     repeatable: false,
  33.                     optional: false
  34.                   },
  35.                   {
  36.                     name: '成员',
  37.                     repeatable: false,
  38.                     optional: false
  39.                   },
  40.                   {
  41.                     name: '属性',
  42.                     repeatable: false,
  43.                     optional: false
  44.                   }
  45.                 ]
  46.               }
  47.             )
  48.           }
  49.         }
  50.         const _this = this
  51.         EPMMemberProperty.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  52.         EPMMemberProperty.prototype.defaultValue = function () { return 'Loading...'; }
  53.         EPMMemberProperty.prototype.evaluateAsync  = (context, ...arg) => {
  54.           console.log('context', context)
  55.           const { row, col } = context
  56.           const cell = this.sheetST.getCell(row, col);
  57.           const formula = cell.formula();
  58.           _this.getFormatResult(formula).then(function(response){
  59.               console.log('adffff', response)
  60.               context.setAsyncResult(response);
  61.           })
  62.         };
  63.         GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("EPMMemberProperty", new EPMMemberProperty());
  64.         this.sheetST.addCustomFunction(new EPMMemberProperty());
  65.       }
复制代码

回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2024-3-22 12:12:06
地板
如1楼所述,您是否是在designer 插入函数 弹窗中自定义添加了该自定义函数呢?
image.png669838866.png
具体实现方案也请一并说明下,我们实际验证看看。
回复 使用道具 举报
sssf
注册会员   /  发表于:2024-3-22 15:53:50
5#
Lynn.Dou 发表于 2024-3-22 12:12
如1楼所述,您是否是在designer 插入函数 弹窗中自定义添加了该自定义函数呢?

具体实现方案也请一并说 ...

  1. <!-- 设置表样-->

  2. <template>
  3.   <div style="height: 500px;">
  4.     <gc-spread-sheets-designer
  5.         style="height: 500px;"
  6.         ref="spreadWrapRef"
  7.         :config="config"
  8.         :spreadOptions="spreadOptions"
  9.     />
  10.   </div>
  11.   </template>
  12.   <script>
  13.   import GC from '@/utils/help/import-spread'
  14.   import {initSheetData, initSpreadStyle, stopRenderingTask} from '@/utils/help/render-spread-data'
  15.   export default {
  16.     name: 'spreadWrap', //设置表样
  17.     props: {
  18.     },
  19.     data() {
  20.       return {
  21.         spreadLoading: false, //组件加载
  22.         spreadOptions: {
  23.           sheetCount: 1,
  24.         },
  25.         renderConfig: {
  26.           emitLoadRate: this.emitLoadRate
  27.         },
  28.         config: Object.freeze(JSON.parse(JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig))),
  29.       };
  30.     },
  31.     methods: {
  32.       defindFunction() {
  33.         function customFontFamilyInFormatDialogTemplate(templateNode) {
  34.         
  35.           if (templateNode.bindingPath && templateNode.bindingPath === 'functionDesc.allFunction' && templateNode.items) {
  36.   
  37.             templateNode.items.unshift({ text: "获取成员属性", value: "EPMMemberProperty" })
  38.   
  39.             return;
  40.           }
  41.           let nodes = templateNode.content || templateNode.children;
  42.           if (nodes && nodes instanceof Array) {
  43.             nodes.forEach((subNode) => customFontFamilyInFormatDialogTemplate(subNode));
  44.           }
  45.         }
  46.         
  47.         var template = GC.Spread.Sheets.Designer.getTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate);
  48.         customFontFamilyInFormatDialogTemplate(template);
  49.         GC.Spread.Sheets.Designer.registerTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate, template);
  50.   
  51.         // 自定义公式一
  52.         function EPMMemberProperty() {
  53.           this.maxArgs = 3;
  54.           this.minArgs = 1;
  55.           this.name = 'EPMMemberProperty'
  56.           this.description = function () {
  57.             return (
  58.               {
  59.                 description: "获取指定成员的指定属性值",
  60.                 parameters: [
  61.                   {
  62.                     name: '连接名称',
  63.                     repeatable: false,
  64.                     optional: false
  65.                   },
  66.                   {
  67.                     name: '成员',
  68.                     repeatable: false,
  69.                     optional: false
  70.                   },
  71.                   {
  72.                     name: '属性',
  73.                     repeatable: false,
  74.                     optional: false
  75.                   }
  76.                 ]
  77.               }
  78.             )
  79.           }
  80.         }
  81.         const _this = this
  82.         EPMMemberProperty.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
  83.         EPMMemberProperty.prototype.defaultValue = function () { return 'Loading...'; }
  84.         EPMMemberProperty.prototype.evaluateAsync  = (context, ...arg) => {
  85.           console.log('context', context, arg)
  86.           const { row, col } = context
  87.           const cell = this.sheetST.getCell(row, col);
  88.           const formula = cell.formula();
  89.           _this.asyncData(formula).then(function(response){
  90.               context.setAsyncResult(response);
  91.           })
  92.         };
  93.         GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("EPMMemberProperty", new EPMMemberProperty());
  94.         this.sheetST.addCustomFunction(new EPMMemberProperty());
  95.         // this.sheetST.setFormula(2, 2, '=ASUM(A1,B1)')
  96.       },
  97.       asyncData(args){
  98.         return new Promise(resolve => {
  99.           setTimeout(() => {
  100.           return resolve('异步返回值')
  101.         }, 5000)
  102.         })
  103.   
  104.       },
  105.       async initPage(){
  106.         this.spreadST = new GC.Spread.Sheets.Designer.findControl(this.$refs.spreadWrapRef.$el).getWorkbook();
  107.         this.sheetST = this.spreadST.getActiveSheet()
  108.         this.defindFunction()
  109.       },
  110.     },
  111.     mounted() {
  112.       this.initPage()
  113.     }
  114.   };
  115.   </script>
  116.   <style lang="scss" scoped>
  117.   
  118.   </style>
  119.   
复制代码


上面是完整的代码了

至于你说的  是否是在designer 插入函数  我不是很理解,我只是自定义了一个函数,然后通过  【FX】这个按钮给单元格设置了这个自定义公式,然后在弹窗里设置参数

我重新描述一下我的问题:公式我设置了三个参数 ,但使用的时候我赋值了第二参数,如果第一个参数没有手动给个空格,那么公式保存后再变成  EPMMemberProperty("b10")  ,我希望即使没给空格,也能直接是  EPMMemberProperty("", "b10", "") 这样的效果
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-22 17:40:31
6#
问题收到,这边调研一下,后续有进展我会在本帖中回复您。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-3-25 11:23:30
7#
您好,我用您的代码测试了一下,目前的表现为没有输入参数的属性将不会有任何输出:

image.png755672301.png

关于您的需求“如果第一个参数没有手动给个空格,那么公式保存后再变成 EPMMemberProperty("b10")  ,我希望即使没给空格,也能直接是EPMMemberProperty("", "b10", "") 这样的效果”。

目前没有办法实现,在Excel和SpreadJS中,只有您输入了值以后才会在公式中显示,这是目前产品的设计,如果您希望最后的结果包含空字符串,只能在输入公式的时候手动添加空字符串:

image.png674612426.png
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-4-9 13:38:58
8#
您好,由于本帖较长时间没有回复,本帖先做结贴处理了,后续如您有其他问题,欢迎您开新帖提问。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部