Is there any way we can export the Antd table data into an excel sheet on button click with reactjs

Viewed 3187

I am new to reactjs. I got a scenario in which the Antd table data need to be exported to an excel sheet on a button click. Is there any default options available with Antd? or we need to do some custom development for same. Any pointers will be appreciated.

Thanks

1 Answers

You can use library react-csv to convert the table data into an .csv file. You can refer to the docs for the onClick props.

import { CSVLink } from "react-csv";
            
    <CSVLink
        data={data}
        onClick={() => {
        console.log("clicked") 
        }}
    >
    Download me
    </CSVLink>
        
    <Table
       columns={columns}
       dataSource={data}
    />
Related