import React from 'react';
import * as XLSX from 'xlsx';
const sheetConfigs = [
{
sheetName: 'TitleDetails',
sheetData: [
{ title: 'Title1', details: 'Details1' },
{ title: 'Title2', details: 'Details2' },
{ title: 'Title3', details: 'Details3' },
],
},
{
sheetName: 'KeyContacts',
sheetData: [
{ name: 'Name1', email: 'Email1', phone: 'Phone1' },
{ name: 'Name2', email: 'Email2', phone: 'Phone2' },
{ name: 'Name3', email: 'Email3', phone: 'Phone3' },
],
},
{
sheetName: 'AssaysVendors',
sheetData: [
{ assay: 'Assay1', vendor: 'Vendor1', price: '$100' },
{ assay: 'Assay2', vendor: 'Vendor2', price: '$200' },
{ assay: 'Assay3', vendor: 'Vendor3', price: '$300' },
],
},
];
const DownloadExcel = () => {
const handleDownload = () => {
const wb = XLSX.utils.book_new();
sheetConfigs.forEach(({ sheetData, sheetName }) => {
const ws = XLSX.utils.json_to_sheet(sheetData);
XLSX.utils.book_append_sheet(wb, ws, sheetName);
});
const filename = `BOP_Plan_${Date.now()}.xlsx`;
XLSX.writeFile(wb, filename, { bookType: 'xlsx' });
};
return (
<>
<button onClick={handleDownload}>Download Excel</button>
</>
);
};
export default DownloadExcel;