- import React, { useState, useEffect } from 'react';
- import '@grapecity/spread-sheets-resources-zh';
- import GC from '@grapecity/spread-sheets';
- import '@grapecity/spread-sheets-print';
- import '@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css';
- import { SpreadSheets, Worksheet } from '@grapecity/spread-sheets-react';
- const Demo = () => {
- let timer = null;
- const [time, setTime] = useState(3600);
- useEffect(() => {
- timeTransition();
- }, []);
- const timeTransition = () => {
- clearInterval(timer);
- timer = setInterval(() => setTime(t => --t), 1000);
- };
- const workbookInit = (spread) => {
- const sheet = spread.getActiveSheet();
- const spreadNS = GC.Spread.Sheets;
- const gcdv = spreadNS.DataValidation;
- let ddv = null;
- ddv = gcdv.createListValidator('1,2,3');
- ddv.inputTitle('Please choose a category:');
- ddv.inputMessage('1, 2, 3');
- ddv.inCellDropdown(true);
- sheet.setDataValidator(0, 0, 1, 1, ddv);
- };
- const hostStyle = {
- width: '100%',
- height: '100%'
- };
- return (
- <div style={{ width: '100vw', height: '100vh' }}>
- <div>{time}</div>
- <SpreadSheets
- hostStyle={hostStyle}
- workbookInitialized={(e) => {
- workbookInit(e);
- }}
- >
- <Worksheet />
- </SpreadSheets>
- </div>
- );
- };
- export default Demo;
复制代码
这段代码需要在react项目中运行,这个数据校验框难以选中。 |