本帖最后由 Universail 于 2024-6-8 17:17 编辑
原来自定义公式是可以提示的,现在死活就不提示了,没找到哪里写错了
单独写在一个vue组件文件中:
- <script lang="ts" setup>
- import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
- import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2016colorful.css";
- import "@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css";
- import GC from "@grapecity-software/spread-sheets";
- import "@grapecity-software/spread-sheets-pdf";
- import "@grapecity-software/spread-sheets-print";
- import "@grapecity-software/spread-sheets-shapes";
- import "@grapecity-software/spread-sheets-slicers";
- import "@grapecity-software/spread-sheets-tablesheet";
- import "@grapecity-software/spread-sheets-reportsheet-addon";
- import "@grapecity-software/spread-sheets-formula-panel";
- import "@grapecity-software/spread-sheets-resources-zh";
- import "@grapecity-software/spread-sheets-designer-resources-cn";
- import "@grapecity-software/spread-sheets-designer-resources-en";
- import GCDesigner from "@grapecity-software/spread-sheets-designer";
- import GcSpreadSheetsDesignerVue from "@grapecity-software/spread-sheets-designer-vue";
- import { _t } from "@src/i18n";
- import { routerInst } from "@src/router";
- import { IStore as IMdaAgileReportStore } from "@src/store/MultidimensionalAnalysis/AgileReport/use_store";
- import { cloneDeep } from "lodash-es";
- type IProps = { store: IMdaAgileReportStore };
- const props = withDefaults(defineProps<IProps>(), {});
- const spreadRef = ref();
- const { toggle, enter, exit, isFullscreen, isSupported } = useFullscreen(spreadRef);
- // @ts-ignore
- let fontFamilyCommand = GC.Spread.Sheets.Designer.getCommand(GC.Spread.Sheets.Designer.CommandNames.FontFamily);
- fontFamilyCommand.dropdownList.unshift({ text: "宋体", value: "simsun" }, { text: "宋体(粗)", value: "simsunbd" }, { text: "微软雅黑", value: "msyh" });
- GC.Spread.Common.CultureManager.culture("zh-cn");
- const designerConfig = cloneDeep(GCDesigner.Spread.Sheets.Designer.DefaultConfig);
- // @ts-ignore
- designerConfig.ribbon?.unshift({
- id: "actions",
- text: _t("actions"),
- buttonGroups: [
- {
- label: "",
- thumbnailClass: "",
- commandGroup: {
- children: [
- {
- direction: "horizontal",
- commands: ["save", "archive"],
- },
- ],
- },
- },
- {
- label: "execute",
- thumbnailClass: "",
- commandGroup: {
- children: [
- {
- direction: "vertical",
- commands: ["execute"],
- },
- ],
- },
- },
- ],
- });
- designerConfig.contextMenu?.unshift("pasteFormulaMD", "fullscreen");
- designerConfig.commandMap = {
- save: {
- title: _t("save"),
- text: _t("save"),
- iconClass: "uc-spread-save",
- bigButton: "false",
- commandName: "save",
- execute: async (context, propertyName, fontItalicChecked) => {
- await props.store.activeInst.viewer.saveState();
- },
- },
- archive: {
- title: _t("archive"),
- text: _t("archive"),
- iconClass: "uc-spread-archive",
- bigButton: "false",
- commandName: "archive",
- execute: async (context, propertyName, fontItalicChecked) => {},
- },
- execute: {
- title: _t("execute"),
- text: _t("execute"),
- iconClass: "uc-spread-execute",
- bigButton: "false",
- commandName: "execute",
- execute: async (context, propertyName, fontItalicChecked) => {
- await props.store.activeInst.viewer.execute();
- },
- },
- pasteFormulaMD: {
- text: "粘贴多维公式",
- commandName: "pasteFormulaMD",
- visibleContext: "clickViewPort",
- subCommands: ["pasteFormulaMDAbsolute", "pasteFormulaMDRelative"],
- },
- pasteFormulaMDAbsolute: {
- text: "绝对引用",
- commandName: "pasteFormulaMDAbsolute",
- execute: () => {
- props.store.activeInst.viewer.pasteAbsoluteQueryFormula();
- },
- },
- pasteFormulaMDRelative: {
- text: "相对引用",
- commandName: "pasteFormulaMDRelative",
- execute: () => {
- props.store.activeInst.viewer.pasteRelativeQueryFormula();
- },
- },
- fullscreen: {
- text: "全屏",
- commandName: "fullscreen",
- execute: async () => {
- await toggle();
- },
- },
- };
- // @ts-ignore
- designerConfig.commandMap[GC.Spread.Sheets.Designer.CommandNames.FontFamily] = fontFamilyCommand;
- let timer: NodeJS.Timeout | null = null;
- function onSave(event: KeyboardEvent) {
- if (!routerInst.currentRoute.value.fullPath?.includes("/boot/mda_agile_report/")) return;
- const ctrlKey = event.ctrlKey || event.metaKey;
- if (ctrlKey && event.key === "s") {
- event.preventDefault();
- if (timer !== null) {
- clearTimeout(timer);
- }
- timer = setTimeout(() => {
- props.store.activeInst.viewer.saveState();
- }, 1000);
- }
- }
- const viewPortWidthRef = ref(0);
- const viewPortHeightRef = ref(0);
- onMounted(() => {
- viewPortWidthRef.value = window.innerWidth;
- viewPortHeightRef.value = window.innerHeight;
- document.addEventListener("keydown", onSave);
- });
- onUnmounted(() => {
- document.removeEventListener("keydown", onSave);
- });
- function onDesignerInitialized(designer: GCDesigner.Spread.Sheets.Designer.Designer) {
- designer.setData("isRibbonCollapse", true);
- const workBook = designer.getWorkbook() as GC.Spread.Sheets.Workbook;
- workBook.options.allowDynamicArray = true;
- workBook.options.scrollbarMaxAlign = true;
- workBook.options.tabStripVisible = true;
- function FactorialFunction() {}
- FactorialFunction.prototype = new GC.Spread.CalcEngine.Functions.Function("U.Test1", 1, 1);
- FactorialFunction.prototype.evaluate = function (arg) {
- console.log(arg);
- };
- const factorial = new FactorialFunction();
- const sheet = workBook.getActiveSheet();
- sheet.addCustomFunction(factorial);
- }
- </script>
- <template>
- <GcSpreadSheetsDesignerVue
- ref="spreadRef"
- :style="{ height: viewPortHeightRef - 70 + 'px' }"
- :config="designerConfig"
- :spreadOptions="props.store.activeInst.viewer.spreadOptions"
- @designerInitialized="(designer) => onDesignerInitialized(designer)"
- />
- </template>
- <style scoped></style>
复制代码 还是不生效,自定义公式不提示
|
|