import React, { useEffect, useState } from 'react';
import * as XLSX from 'xlsx'
import { useQuery } from '@tanstack/react-query';
const Excl = ({userDatas}) => {
let xlDatas = []
const handleExportExcl = (userDatas) => {
userDatas.map(xlData => {
xlDatas.push(xlData)
})
const wb = XLSX.utils.book_new(),
ws = XLSX.utils.json_to_sheet(xlDatas)
XLSX.utils.book_append_sheet(wb, ws, "MySheet");
XLSX.writeFile(wb, "MyExcel.xlsx")
}
return (
<span onClick={() => handleExportExcl(userDatas)} ><span className='flex justify-center items-center'> <span className='mr-3'></span>EXCEL </span> </span>
);
};
export default Excl;
我想要一个Excel工作表,自定义标题作为一列。这是我的代码。我从另一个组件中获取userDatas。
1条答案
按热度按时间f2uvfpb91#
这是https://www.npmjs.com/package/xlsx-lite中的示例。