/* sheetjs (C) SheetJS -- https://sheetjs.com */ import './App.css' import { useCallback, useState } from '@lynx-js/react' import SheetJSLogo from './assets/SheetJS-logo.png'; import { read, utils, WorkSheet } from 'xlsx'; const make_width = (ws: WorkSheet): number[] => { const aoa = utils.sheet_to_json(ws, { header: 1 }), res: number[] = []; aoa.forEach((r: any) => { r.forEach((c: any, C: any) => { res[C] = Math.max(res[C] || 60, String(c).length * 10); }); }); for (let C = 0; C < res.length; ++C) if (!res[C]) res[C] = 60; return res; }; export function App() { const [data, setData] = useState([ "SheetJS".split(""), [5, 4, 3, 3, 7, 9, 5], [8, 6, 7, 5, 3, 0, 9] ]); const [widths, setWidths] = useState(Array.from({ length: 7 }, () => 20)); const importFile = useCallback(async () => { try { const ab = await (await fetch("https://docs.sheetjs.com/pres.numbers")).arrayBuffer(); const wb = read(ab); /* convert first worksheet to AOA */ const wsname = wb.SheetNames[0]; const ws = wb.Sheets[wsname]; const data = utils.sheet_to_json(ws, { header: 1 }); /* update state */ setData(data); console.log(data); setWidths(make_width(ws)); } catch (err) { console.log("importFile Error", "Error " + ((err as any).message || err)); } }, []); return (   SheetJS × React Lynx IMPORT DATA FROM A SPREADSHEET Current Data {data.map((row, rowIndex) => ( {Array.isArray(row) && row.map((cell, cellIndex) => ( {cell} ))} ))} ) }