贴吧王大锤
注册会员 / 发表于:7 分钟前地板
贴吧王大锤 发表于 2021-7-5 17:55
运行时报错
TypeError: Cannot read property 'name' of undefined
import React, { FC } from 'react';
import GC from '@grapecity/spread-sheets';
import { SpreadSheets, Worksheet } from '@grapecity/spread-sheets-react';
import * as spreadExcel from '@grapecity/spread-excelio';
console.log(spreadExcel);
// eslint-disable-next-line max-len
const SpreadJSKey = '';
GC.Spread.Sheets.LicenseKey = SpreadJSKey;
(spreadExcel as any).LicenseKey = SpreadJSKey;
interface ExcelProps {
url: string,
}
const Excel: FC<ExcelProps> = ({ url }: ExcelProps) => {
const importFile = (spread: any) => {
const excelIO = new spreadExcel.IO();
const request = new XMLHttpRequest();
request.open('get', url, true);
request.responseType = 'blob';
request.onload = () => {
const blob = request.response;
excelIO.open(blob, (json: Object) => {
spread.fromJSON(json);
}, (e: string) => {
console.log(e);
});
};
request.send(null);
};
const excelInit = (spread: any) => {
// setWorkbook(spread);
importFile(spread);
};
return (
<div>
<SpreadSheets
workbookInitialized={excelInit}
>
<Worksheet />
</SpreadSheets>
</div>
);
};
export default Excel; |
|