[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
        
(Showing Draft Content)

授权常见问题

本文总结了授权问题的常见几种情况及处理方式

在遇到授权问题时,首先需要验证清空缓存后是否还有问题,如果问题仍然存在,请接着看下面文章

从授权的表现形式上来看,出错的授权一般有三种表现形式:

一、提示:授权未找到(License not found)

image

image

出现此问题的原因是没有加入授权或者加入授权方式不正确。如已加入授权请检查:

1. 授权变量是否输入正确;GC.Spread.Sheets.LicenseKey 是否有拼写错误。

2. 授权设置代码是否在初始化 SpreadJS 控件之前,一般在引用完 SpreadJS 资源后直接加入授权代码。

二、提示:无效许可证(Invalid license key)

image

image

出现此问题说明添加授权的方式没有问题,原因可能是授权和当前网站地址不匹配或者和使用版本不匹配。

请检查以下几点:

1. 确认授权和 SpreadJS 使用版本是否一致。

SpreadJS的部署授权是一个大版本中通用的,例如V14的部署授权可以在V14.1中使用。但是V13的部署授权无法在V14的版本中使用,需要联系商务进行升级。

2. 确认授权的网站地址与当前网页地址是否匹配。

  1. 是否存在授权为IP地址,网页地址是对应的域名(在SpreadJS的部署授权中,域名和IP是分开的,如果是域名的授权就只能通过对应的域名进行访问。同理IP也是一样)。

  2. 如果SpreadJS页面是在iframe中的,那么授权应该对应的是iframe中的地址而非浏览器地址栏的地址。

  3. 一些浏览器在输入地址的时候会自动省略www的开头。这里要确认真正的域名是否包含www。如果真正的域名包含www,那么部署授权一定也要是包含www的对应域名的授权,反之则不包含。遇到这样的情况,可以通过在浏览器控制台中输入window.location.hostname进行判断,该结果需要与部署授权保持一致。

3. 确认授权是否复制/输入完整。

  1. 由于SpreadJS的部署授权较长,通常通过邮件发送的时候,可能会被用户忽略掉超出邮件页面显示的部分(注意邮件中的滚动条)。

  2. 有些用户在复制授权的时候会忽略掉授权逗号之前的前缀,这样做会导致授权不正确。所以在复制的时候需要完全复制。

  3. 可以通过代码中输出license或控制台查看下GC对象中的license,对比是否与设置的授权码一致。比如,当授权码中包含&符号时,可能会由于授权对象的进一步封装调用,导致被转义为&从而使授权码无效。

  4. 如果是有时间限制的正式授权,在过期之后也会出现无效许可证的提示,符合这种情况请优先检查授权是否过期。

三、提示:临时部署授权已过期(temporary deployment key has expired)

image

image

出现此问题说明申请的临时部署授权过期了,这个时候请联系我们的商务同事。

四、其他问题

如果上述情况不能解决您的问题,请看下面问题整理。此处问题均为用户实际遇到的问题,如果您也有类似情况,请按照记载的解决方法进行处理。

1. SpreadJS正常运行,已经去掉水印提示。但是导入Excel文件之后发现多了一个提示授权的sheet(有些情况下也可能导入后只剩这一个sheet)。并显示授权未找到。

这种情况有两个原因,第一种是在VUE,React,Angular框架中(如果没有用上述框架可以直接跳过往后看)。在上述框架中ExcelIO(导入导出)模块需要单独授权。发生上述问题原因就是只授权了SpreadJS,没有对ExcelIO进行授权。在授权时需要同时对SpreadJS和ExcelIO进行授权,例如下面代码:

import React from 'react';
import './App.css';
import GC from '@grapecity-software/spread-sheets';
import { SpreadSheets, Worksheet } from '@grapecity-software/spread-sheets-react';

// 导入ExcelIO模块
import * as spreadExcel from '@grapecity-software/spread-excelio';

// 导入文件保存模块
import saveAs from 'file-saver';

//同时对SpreadJS与ExcelIO进行授权
GC.Spread.Sheets.LicenseKey = spreadExcel.LicenseKey = "your key";

另一个可能出现上述问题的原因,该Excel文件可能经过试用版导出过,试用版导出的时候同样会创建一个提示授权的sheet。虽然后面部署了正式版本,但是导入的文件中已经存在了这个sheet,用正式版导入只能说不再新建,但是既有的不会删除。针对这种情况,需要手动找到Excel文件打开并删除掉提示授权的sheet。之后就可以正常导入了。

2.授权已经正确加入并排除了代码书写和位置问题。但结果提示授权未找到。

这种情况只有在框架下会发生。 这种情况有可能是因为打包问题导致,不同的打包策略下,有可能出现生成多个GC命名空间的情况。导致授权没有加到真正使用的GC命名空间上。目前已知cnpm在某种情况下可能会出现上述情况。如果用户使用的是cnpm,请将package-lock.json文件和node_modules文件夹删除后,更换成源生的npm源。重新npm install 后打包运行。

3.使用在线表格编辑器时,控制台出现register相关错误

这里注意在线表格编辑器页面中import的顺序和授权的引用顺序,具体顺序参考在线表格编辑器安装包中的sample文件。下面附一个react框架下的引用顺序供参考:

import React from 'react';
import * as GC from '@grapecity-software/spread-sheets';
import "@grapecity-software/spread-sheets-pivot-addon";
import '@grapecity-software/spread-sheets-resources-zh';
import '@grapecity-software/spread-sheets-designer-resources-cn';
import {Designer} from '@grapecity-software/spread-sheets-designer-react';
import "@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css"
import "@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"
import "./custom.css"
4.使用在线表格编辑器时,控制台出现PDF与tQa相关错误

错误原因可能会有两种情况

  1. 注意package.json中引用的SpreadJS版本号后有没有向上的箭头,如下图红框所示image

    加上箭头代表有更高的版本就用更高的版本进行适配,这就会导致SpreadJS相关引用的版本不能保持一致,导致错误。

    该箭头要么所有的SpreadJS相关引用都加上,要么都去掉。不能一部分有,一部分没有。另外,SpreadJS相关引用的版本一定要保持一致,都用一个版本。

  2. tQa可能会出现在导出PDF时,导出PDF相关功能需引入print 打印的相关js文件。存在着引用的先后关系。print需在先,PDF在后。引用顺序错误也会出现tQa的错误。

5.授权出现 Cannot set property 'LicenseKey' of undefined 相关错误

image

上述问题一般出现在V13升级到V14的过程中,并且引用了ExcelIO功能。在V13中支持下面两种写法:

import * as ExcelIO from "@grapecity-software/spread-excelio";
import ExcelIO from "@grapecity-software/spread-excelio";

其中这样的写法:import ExcelIO from "@grapecity-software/spread-excelio"; 在V14版本之后不被支持。目前仅支持

import * as ExcelIO from "@grapecity-software/spread-excelio";

这一种import方式。之前使用import ExcelIO from "@grapecity-software/spread-excelio";这样写法的用户在升级之后就会出现Cannot set property 'LicenseKey' of undefined的错误。

解决方法是将import ExcelIO from "@grapecity-software/spread-excelio"改为import * as ExcelIO from "@grapecity-software/spread-excelio";

作者: Grapecity.China | 审核:Ellia.Duan | 更新时间:2023.12.15