Last active
February 5, 2024 14:44
-
-
Save medoevruslan/9cf3c7b5f007b2575f2e27dbc079326c to your computer and use it in GitHub Desktop.
example hwo to export data to excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as XLSX from 'xlsx' | |
| const handleExportExcel = () => { | |
| const filename = 'members.xlsx' | |
| const wsData = [ | |
| ['First Name', 'Last Name', 'Email', 'Unique ID', 'Plan Name', 'Status'], | |
| // Loop through the filtered users array and extract the required data | |
| ...filteredUsers.map((user) => [ | |
| user.first_name, | |
| user.last_name, | |
| user.email, | |
| user.unique_id, | |
| user.account_type, | |
| user.activated === false ? 'Inactive' : 'Active', | |
| ]), | |
| ] | |
| const ws = XLSX.utils.aoa_to_sheet(wsData) | |
| const wb = XLSX.utils.book_new() | |
| XLSX.utils.book_append_sheet(wb, ws, 'Members') | |
| XLSX.writeFile(wb, filename) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment