本帖最后由 y.a.n 于 2021-8-31 17:28 编辑
const GC:any = require('./spreadJs/gc.spread.sheets.all.11.2.2.min.js')
import { IO } from "@grapecity/spread-excelio";const TestContent = (props:any) => {
const spreadRef = useRef<any>({})
useEffect ( () =>{
const createSpreadSheet = async() => {
if (typeof GC === 'undefined') {
loadSpread();
} else {
spreadRef.current = new GC.Spread.Sheets.Workbook(spreadRef.current, {
sheetCount: 2,
newTabVisible: false,
tabEditable: false,
});
let excelIO = new IO();
const resData = await getReportExcelData({ // 获取接口数据
repCode:"JA0020",
orgId:"10",
repDate:"202107"
});
// 测试已拿到
excelIO.open(resData, (json: any)=> {
let workbookObj = json.sheets;
// console.log("!!!!!!!!workbookObj",workbookObj);
if(workbookObj){
setExcelData(workbookObj[Object.keys(workbookObj)[0]].data.dataTable);
excelDataRef.current = workbookObj[Object.keys(workbookObj)[0]].data.dataTable;
}
spreadRef.current.fromJSON(json);
// spreadRef.current.options.backColor = 'aliceblue';
}, function (e:any) {
// process error
alert(e.errorMessage);
}, {});
}
};
createSpreadSheet()
},[])
return (
<div style={hostStyle}>
<div ref={e => spreadRef.current = e} className={styles.statementBox}>
</div>
</div>
);
}
|