excel等表格文件前端解析
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
keyArr | 对应excel列英文字段 | Array | [] |
onBeforImport | 文件自定义校验 | Function(data: {}) => void | () => {} |
onImportFile | 拿到解析后对json数据处理函数 | Function(data: Array) => void | () => {} |
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ImportSheet from 'see-materilas-import-sheet';
class App extends Component {
constructor(props) {
super(props);
this.state = {
importList: []
};
}
checkFile = (file) => {
console.log(file);
};
importFile = (data) => {
this.setState({
importList: data
});
};
render() {
return (
<div>
<ImportSheet onBeforImport={this.checkFile} key={1} onImportFile={this.importFile} />
<ImportSheet key={2} onImportFile={this.importFile}>
<span>自定义上传组件</span>
</ImportSheet>{' '}
<div>{JSON.stringify(this.state.importList)}</div>
</div>
);
}
}
ReactDOM.render(<App />, mountNode);