- <!-- 设置表样-->
- <template>
- <div style="height: 500px;">
- <gc-spread-sheets-designer
- style="height: 500px;"
- ref="spreadWrapRef"
- :config="config"
- :spreadOptions="spreadOptions"
- />
- </div>
- </template>
- <script>
- import GC from '@/utils/help/import-spread'
- import {initSheetData, initSpreadStyle, stopRenderingTask} from '@/utils/help/render-spread-data'
- export default {
- name: 'spreadWrap', //设置表样
- props: {
- },
- data() {
- return {
- spreadLoading: false, //组件加载
- spreadOptions: {
- sheetCount: 1,
- },
- renderConfig: {
- emitLoadRate: this.emitLoadRate
- },
- config: Object.freeze(JSON.parse(JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig))),
- };
- },
- methods: {
- defindFunction() {
- function customFontFamilyInFormatDialogTemplate(templateNode) {
-
- if (templateNode.bindingPath && templateNode.bindingPath === 'functionDesc.allFunction' && templateNode.items) {
-
- templateNode.items.unshift({ text: "获取成员属性", value: "EPMMemberProperty" })
-
- return;
- }
- let nodes = templateNode.content || templateNode.children;
- if (nodes && nodes instanceof Array) {
- nodes.forEach((subNode) => customFontFamilyInFormatDialogTemplate(subNode));
- }
- }
-
- var template = GC.Spread.Sheets.Designer.getTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate);
- customFontFamilyInFormatDialogTemplate(template);
- GC.Spread.Sheets.Designer.registerTemplate(GC.Spread.Sheets.Designer.TemplateNames.InsertFunctionDialogTemplate, template);
-
- // 自定义公式一
- function EPMMemberProperty() {
- this.maxArgs = 3;
- this.minArgs = 1;
- this.name = 'EPMMemberProperty'
- this.description = function () {
- return (
- {
- description: "获取指定成员的指定属性值",
- parameters: [
- {
- name: '连接名称',
- repeatable: false,
- optional: false
- },
- {
- name: '成员',
- repeatable: false,
- optional: false
- },
- {
- name: '属性',
- repeatable: false,
- optional: false
- }
- ]
- }
- )
- }
- }
- const _this = this
- EPMMemberProperty.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- EPMMemberProperty.prototype.defaultValue = function () { return 'Loading...'; }
- EPMMemberProperty.prototype.evaluateAsync = (context, ...arg) => {
- console.log('context', context, arg)
- const { row, col } = context
- const cell = this.sheetST.getCell(row, col);
- const formula = cell.formula();
- _this.asyncData(formula).then(function(response){
- context.setAsyncResult(response);
- })
- };
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("EPMMemberProperty", new EPMMemberProperty());
- this.sheetST.addCustomFunction(new EPMMemberProperty());
- // this.sheetST.setFormula(2, 2, '=ASUM(A1,B1)')
- },
- asyncData(args){
- return new Promise(resolve => {
- setTimeout(() => {
- return resolve('异步返回值')
- }, 5000)
- })
-
- },
- async initPage(){
- this.spreadST = new GC.Spread.Sheets.Designer.findControl(this.$refs.spreadWrapRef.$el).getWorkbook();
- this.sheetST = this.spreadST.getActiveSheet()
- this.defindFunction()
- },
- },
- mounted() {
- this.initPage()
- }
- };
- </script>
- <style lang="scss" scoped>
-
- </style>
-
复制代码
上面是完整的代码了
至于你说的 是否是在designer 插入函数 我不是很理解,我只是自定义了一个函数,然后通过 【FX】这个按钮给单元格设置了这个自定义公式,然后在弹窗里设置参数
我重新描述一下我的问题:公式我设置了三个参数 ,但使用的时候我赋值了第二参数,如果第一个参数没有手动给个空格,那么公式保存后再变成 EPMMemberProperty("b10") ,我希望即使没给空格,也能直接是 EPMMemberProperty("", "b10", "") 这样的效果 |