Skip to content

Instantly share code, notes, and snippets.

@medoevruslan
Last active February 5, 2024 14:44
Show Gist options
  • Save medoevruslan/9cf3c7b5f007b2575f2e27dbc079326c to your computer and use it in GitHub Desktop.
Save medoevruslan/9cf3c7b5f007b2575f2e27dbc079326c to your computer and use it in GitHub Desktop.
example hwo to export data to excel
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