import Head from 'next/head';
import { read, utils } from 'xlsx';
import base64 from "@/sheetjs.xlsx";
export default function Index({type, html, name}) { return ( <>
{`SheetJS Next.JS ${type} Demo`}
{`SheetJS Next.JS ${type} Demo`}
This demo reads from /sheetjs.xlsx
Sheet name: {name}
> ); }
let cache = [];
export async function getStaticProps(ctx) {
if(!cache || !cache.length) {
const wb = read(base64, {type: "base64"});
cache = wb.SheetNames.map((name) => ({ name, sheet: wb.Sheets[name] }));
}
const entry = cache[ctx.params.id];
return {
props: {
type: "getStaticPaths",
name: entry.name,
id: ctx.params.id.toString(),
html: entry.sheet ? utils.sheet_to_html(entry.sheet) : "",
},
}
}
export async function getStaticPaths() {
const wb = read(base64, {type: "base64"});
cache = wb.SheetNames.map((name) => ({ name, sheet: wb.Sheets[name] }));
return {
paths: wb.SheetNames.map((_, idx) => ({ params: { id: idx.toString() } })),
fallback: false,
};
}