import { TableContainer, Table, TableRow, TableCell, TableBody, TableHead } from '@mui/material'; import { WorkBook, WorkSheet, read, utils, writeFileXLSX } from "xlsx"; import { useRef, useState, useEffect } from "react"; import './App.css' interface President { Name: string; Index: number; } function App() { const tbl = useRef(null); const xport = () => { const wb: WorkBook = utils.table_to_book(tbl.current); writeFileXLSX(wb, "SheetJSMaterialUI.xlsx"); }; const [pres, setPres] = useState([]); useEffect(() => { let active = true; (async() => { const ab: ArrayBuffer = await (await fetch("https://docs.sheetjs.com/pres.xlsx")).arrayBuffer(); const wb: WorkBook = read(ab); const ws: WorkSheet = wb.Sheets[wb.SheetNames[0]]; const aoo: President[] = utils.sheet_to_json(ws); if(active) setPres(aoo); })(); return () => { active = false }; }, []); return ( <> NameIndex {pres.map((row, idx) => ( {row.Name} {row.Index} ))}
); } export default App