lay-excel
安装后弄个 Botton 嵌入页面就可以了。
import { ExportOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import { useState } from 'react';
import LAY_EXCEL from 'lay-excel';
type Props = {
data: [];
title: string;
loading: boolean;
};
function ButtonExportExcel(props: Props) {
const [loading, setLoading] = useState(props.loading);
async function onClick() {
setLoading(true);
LAY_EXCEL.exportExcel(props.data, `${props.title}.xlsx`, 'xlsx')
setLoading(false);
}
return (
<Button type="primary" loading={props.loading && loading} size={'small'} icon={<ExportOutlined />} onClick={onClick}>导出Excel</Button>
);
}
export default ButtonExportExcel;