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

QQ登录

只需一步,快速开始

Universail
金牌服务用户   /  发表于:2024-6-8 16:25  /   查看:215  /  回复:6
本帖最后由 Universail 于 2024-6-8 17:17 编辑

image.png385630797.png
image.png744312438.png

原来自定义公式是可以提示的,现在死活就不提示了,没找到哪里写错了


单独写在一个vue组件文件中:
  1. <script lang="ts" setup>
  2. import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
  3. import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
  4. import "@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css";
  5. import GC from "@grapecity-software/spread-sheets";
  6. import "@grapecity-software/spread-sheets-pdf";
  7. import "@grapecity-software/spread-sheets-print";
  8. import "@grapecity-software/spread-sheets-shapes";
  9. import "@grapecity-software/spread-sheets-slicers";
  10. import "@grapecity-software/spread-sheets-tablesheet";
  11. import "@grapecity-software/spread-sheets-reportsheet-addon";
  12. import "@grapecity-software/spread-sheets-formula-panel";
  13. import "@grapecity-software/spread-sheets-resources-zh";
  14. import "@grapecity-software/spread-sheets-designer-resources-cn";
  15. import "@grapecity-software/spread-sheets-designer-resources-en";
  16. import GCDesigner from "@grapecity-software/spread-sheets-designer";
  17. import GcSpreadSheetsDesignerVue from "@grapecity-software/spread-sheets-designer-vue";
  18. import { _t } from "@src/i18n";
  19. import { routerInst } from "@src/router";
  20. import { IStore as IMdaAgileReportStore } from "@src/store/MultidimensionalAnalysis/AgileReport/use_store";
  21. import { cloneDeep } from "lodash-es";

  22. type IProps = { store: IMdaAgileReportStore };
  23. const props = withDefaults(defineProps<IProps>(), {});
  24. const spreadRef = ref();
  25. const { toggle, enter, exit, isFullscreen, isSupported } = useFullscreen(spreadRef);
  26. // @ts-ignore
  27. let fontFamilyCommand = GC.Spread.Sheets.Designer.getCommand(GC.Spread.Sheets.Designer.CommandNames.FontFamily);
  28. fontFamilyCommand.dropdownList.unshift({ text: "宋体", value: "simsun" }, { text: "宋体(粗)", value: "simsunbd" }, { text: "微软雅黑", value: "msyh" });
  29. GC.Spread.Common.CultureManager.culture("zh-cn");
  30. const designerConfig = cloneDeep(GCDesigner.Spread.Sheets.Designer.DefaultConfig);
  31. // @ts-ignore
  32. designerConfig.ribbon?.unshift({
  33.   id: "actions",
  34.   text: _t("actions"),
  35.   buttonGroups: [
  36.     {
  37.       label: "",
  38.       thumbnailClass: "",
  39.       commandGroup: {
  40.         children: [
  41.           {
  42.             direction: "horizontal",
  43.             commands: ["save", "archive"],
  44.           },
  45.         ],
  46.       },
  47.     },
  48.     {
  49.       label: "execute",
  50.       thumbnailClass: "",
  51.       commandGroup: {
  52.         children: [
  53.           {
  54.             direction: "vertical",
  55.             commands: ["execute"],
  56.           },
  57.         ],
  58.       },
  59.     },
  60.   ],
  61. });
  62. designerConfig.contextMenu?.unshift("pasteFormulaMD", "fullscreen");
  63. designerConfig.commandMap = {
  64.   save: {
  65.     title: _t("save"),
  66.     text: _t("save"),
  67.     iconClass: "uc-spread-save",
  68.     bigButton: "false",
  69.     commandName: "save",
  70.     execute: async (context, propertyName, fontItalicChecked) => {
  71.       await props.store.activeInst.viewer.saveState();
  72.     },
  73.   },
  74.   archive: {
  75.     title: _t("archive"),
  76.     text: _t("archive"),
  77.     iconClass: "uc-spread-archive",
  78.     bigButton: "false",
  79.     commandName: "archive",
  80.     execute: async (context, propertyName, fontItalicChecked) => {},
  81.   },
  82.   execute: {
  83.     title: _t("execute"),
  84.     text: _t("execute"),
  85.     iconClass: "uc-spread-execute",
  86.     bigButton: "false",
  87.     commandName: "execute",
  88.     execute: async (context, propertyName, fontItalicChecked) => {
  89.       await props.store.activeInst.viewer.execute();
  90.     },
  91.   },
  92.   pasteFormulaMD: {
  93.     text: "粘贴多维公式",
  94.     commandName: "pasteFormulaMD",
  95.     visibleContext: "clickViewPort",
  96.     subCommands: ["pasteFormulaMDAbsolute", "pasteFormulaMDRelative"],
  97.   },
  98.   pasteFormulaMDAbsolute: {
  99.     text: "绝对引用",
  100.     commandName: "pasteFormulaMDAbsolute",
  101.     execute: () => {
  102.       props.store.activeInst.viewer.pasteAbsoluteQueryFormula();
  103.     },
  104.   },
  105.   pasteFormulaMDRelative: {
  106.     text: "相对引用",
  107.     commandName: "pasteFormulaMDRelative",
  108.     execute: () => {
  109.       props.store.activeInst.viewer.pasteRelativeQueryFormula();
  110.     },
  111.   },
  112.   fullscreen: {
  113.     text: "全屏",
  114.     commandName: "fullscreen",
  115.     execute: async () => {
  116.       await toggle();
  117.     },
  118.   },
  119. };
  120. // @ts-ignore
  121. designerConfig.commandMap[GC.Spread.Sheets.Designer.CommandNames.FontFamily] = fontFamilyCommand;
  122. let timer: NodeJS.Timeout | null = null;
  123. function onSave(event: KeyboardEvent) {
  124.   if (!routerInst.currentRoute.value.fullPath?.includes("/boot/mda_agile_report/")) return;
  125.   const ctrlKey = event.ctrlKey || event.metaKey;
  126.   if (ctrlKey && event.key === "s") {
  127.     event.preventDefault();
  128.     if (timer !== null) {
  129.       clearTimeout(timer);
  130.     }
  131.     timer = setTimeout(() => {
  132.       props.store.activeInst.viewer.saveState();
  133.     }, 1000);
  134.   }
  135. }
  136. const viewPortWidthRef = ref(0);
  137. const viewPortHeightRef = ref(0);
  138. onMounted(() => {
  139.   viewPortWidthRef.value = window.innerWidth;
  140.   viewPortHeightRef.value = window.innerHeight;
  141.   document.addEventListener("keydown", onSave);
  142. });
  143. onUnmounted(() => {
  144.   document.removeEventListener("keydown", onSave);
  145. });
  146. function onDesignerInitialized(designer: GCDesigner.Spread.Sheets.Designer.Designer) {
  147.   designer.setData("isRibbonCollapse", true);
  148.   const workBook = designer.getWorkbook() as GC.Spread.Sheets.Workbook;
  149.   workBook.options.allowDynamicArray = true;
  150.   workBook.options.scrollbarMaxAlign = true;
  151.   workBook.options.tabStripVisible = true;
  152.   function FactorialFunction() {}
  153.   FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function("U.Test1", 1, 1);
  154.   FactorialFunction.prototype.evaluate = function (arg) {
  155.     console.log(arg);
  156.   };
  157.   const factorial = new FactorialFunction();
  158.   const sheet = workBook.getActiveSheet();
  159.   sheet.addCustomFunction(factorial);
  160. }
  161. </script>

  162. <template>
  163.   <GcSpreadSheetsDesignerVue
  164.     ref="spreadRef"
  165.     :style="{ height: viewPortHeightRef - 70 + 'px' }"
  166.     :config="designerConfig"
  167.     :spreadOptions="props.store.activeInst.viewer.spreadOptions"
  168.     @designerInitialized="(designer) => onDesignerInitialized(designer)"
  169.   />
  170. </template>

  171. <style scoped></style>
复制代码
还是不生效,自定义公式不提示

6 个回复

倒序浏览
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-6-11 11:29:51
沙发
您好,看上去您的代码中缺少了Description方法:

image.png699507445.png

  1. FactorialFunction.prototype.description = function () {
  2.   return {
  3.     description: "The function returns the factorial of the cells value",
  4.     parameters: [
  5.       {
  6.         name: "value",
  7.       },
  8.     ],
  9.   };
  10. };
复制代码


您添加上后再试试看。
回复 使用道具 举报
Universail
金牌服务用户   /  发表于:2024-6-11 11:38:31
板凳
Joestar.Xu 发表于 2024-6-11 11:29
您好,看上去您的代码中缺少了Description方法:



我试试吧,这个是老代码了,突然就不行了
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-6-11 13:38:15
地板
好的后续有问题随时追问。
回复 使用道具 举报
Universail
金牌服务用户   /  发表于:2024-6-11 14:01:32
5#
Joestar.Xu 发表于 2024-6-11 13:38
好的后续有问题随时追问。

image.png577842101.png
加了,还是不行,这个写法之前没问题的,突然就不提示自定义公式了
回复 使用道具 举报
Universail
金牌服务用户   /  发表于:2024-6-11 14:06:27
6#
Universail 发表于 2024-6-11 14:01
加了,还是不行,这个写法之前没问题的,突然就不提示自定义公式了

出来了,重启了服务,可以了
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-6-11 16:11:48
7#
好的,问题解决了就好,那就先结贴了,后续有其他问题的话随时开新帖提问哈。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部