npm install --save react-html-table-to-excel
import ReactHTMLTableToExcel from 'react-html-table-to-excel';
constructor(props) {
super(props);
this.tableRef = React.createRef();
}
componentDidMount() {
const table = this.tableRef.current.querySelector('table');
table.setAttribute('id', 'table-to-xls');
}
<div>
<ReactHTMLTableToExcel
id="test-table-xls-button"
className="download-table-xls-button"
table="table-to-xls"
filename="tablexls"
sheet="tablexls"
buttonText="Download as XLS"
/>
//react无法获取自定义组件节点,所以这里要包一层
<div ref={this.tableRef}>
<Table
rowKey={record => record.id}
columns={columns}
dataSource={dataSource}
/>
</div>
</div>
多级表头_前端react + ant design导出多级表头表格
最新推荐文章于 2024-03-02 15:39:14 发布
本文详细介绍了如何在React项目中,结合Ant Design库,有效地实现多级表头的创建和导出功能,为复杂数据展示提供解决方案。
摘要由CSDN通过智能技术生成