import * as XLSX from 'xlsx'
import {timeFormatter} from "@/utils/formatter";

export const exportToExcel = (excelHead, data, sheetName, fileName) => {
    const workBook = XLSX.utils.book_new()
    const dataWithHead = [excelHead, ...data]
    const worksheet = XLSX.utils.json_to_sheet(dataWithHead, {
        skipHeader: true
    })
    XLSX.utils.book_append_sheet(workBook, worksheet, sheetName)
    const fileNameWithTime = fileName + timeFormatter(new Date()) + '.xlsx'
    XLSX.writeFile(workBook, fileNameWithTime)
}