33 lines
964 B
JavaScript
33 lines
964 B
JavaScript
import Head from 'next/head';
|
|
import Link from "next/link";
|
|
import { read } from 'xlsx';
|
|
import base64 from "@/sheetjs.xlsx";
|
|
|
|
export default function Index({type, snames}) { return ( <>
|
|
<Head>
|
|
<meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<title>{`SheetJS Next.JS ${type} Demo`}</title>
|
|
</Head>
|
|
<h3>{`SheetJS Next.JS ${type} Demo`}</h3>
|
|
<p>
|
|
This demo reads from <code>/sheetjs.xlsx</code><br/><br/>
|
|
Each worksheet maps to a path:<br/>
|
|
</p>
|
|
<table><thead><tr key={0}><th>Sheet Name</th><th>URL</th></tr></thead><tbody>
|
|
{snames.map((sname, idx) => (<tr key={idx+1}>
|
|
<td><Link href="/sheets/[id]" as={`/sheets/${idx}`}>{sname}</Link></td>
|
|
<td><code>/sheets/{idx}</code></td>
|
|
</tr>))}
|
|
</tbody></table>
|
|
</> ); }
|
|
|
|
export async function getStaticProps() {
|
|
const wb = read(base64, {type: "base64"});
|
|
return {
|
|
props: {
|
|
type: "getStaticPaths",
|
|
snames: wb.SheetNames,
|
|
},
|
|
}
|
|
}
|