在 react环境下使用 但是会报告 spread.dataManager is not a function - import { FC, useCallback, useEffect, useRef } from 'react'
- import * as GC from '@grapecity/spread-sheets'
- import '@grapecity/spread-sheets-tablesheet'
- import { SpreadSheets } from '@grapecity/spread-sheets-react'
- export const TableSheet: FC = () => {
- const initSpread = useCallback((spread: GC.Spread.Sheets.Workbook) => {
- spread.suspendPaint()
- spread.clearSheets()
- spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader
- const tableName = 'Supplier'
- const dataManager = spread.dataManager()
- const myTable = dataManager.addTable('myTable', {
- remote: {
- read: {
- url: 'https://demodata.grapecity.com/northwind/api/v1/Orders',
- },
- },
- })
- //init a table sheet
- const sheet = spread.addSheetTab(
- 0,
- 'TableSheet1',
- GC.Spread.Sheets.SheetType.tableSheet,
- )
- sheet.options.allowAddNew = false //hide new row
- //bind a view to the table sheet
- void myTable.fetch().then(function () {
- const style = { formatter: 'MM/dd/yyyy' }
- const view = myTable.addView('myView', [
- { value: 'Id', width: 80 },
- { value: 'CompanyName', width: 200, caption: 'Company Name' },
- { value: 'ContactName', width: 150, caption: 'Contact' },
- { value: 'ContactTitle', width: 200, caption: 'Title' },
- { value: 'Address', width: 200 },
- { value: 'City', width: 150, caption: 'City' },
- { value: 'State', width: 100, caption: 'State' },
- { value: 'Region', width: 100, caption: 'Region' },
- ])
- sheet.setDataView(view)
- })
- spread.resumePaint()
- }, [])
- return (
- <SpreadSheets
- workbookInitialized={spread => initSpread(spread)}
- ></SpreadSheets>
- )
- }
复制代码
|