docs.sheetjs.com/docz/static/next/getStaticProps.js

32 lines
908 B
JavaScript
Raw Normal View History

2022-08-16 09:29:15 +00:00
import Head from 'next/head';
2023-05-26 22:50:23 +00:00
import { read, utils } from 'xlsx';
import base64 from "@/sheetjs.xlsx";
2022-08-16 09:29:15 +00:00
2023-05-26 22:50:23 +00:00
export default function Index({type, aoo}) { return ( <>
2022-08-16 09:29:15 +00:00
<Head>
<meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{`SheetJS Next.JS ${type} Demo`}</title>
</Head>
2023-05-26 22:50:23 +00:00
<h3>{`SheetJS Next.JS ${type} Demo`}</h3>
<p>
This demo reads from <code>/sheetjs.xlsx</code><br/><br/>
It generates objects from the first sheet.<br/><br/>
</p>
<table><thead><tr key={0}><th>Name</th><th>Index</th></tr></thead><tbody>
{aoo.map((row, R) => ( <tr key={R+1}>
<td>{row.Name}</td>
<td>{row.Index}</td>
</tr>))}
</tbody></table>
</> ); }
2022-08-16 09:29:15 +00:00
export async function getStaticProps() {
2023-05-26 22:50:23 +00:00
const wb = read(base64, {type: "base64"});
2022-08-16 09:29:15 +00:00
return {
props: {
type: "getStaticProps",
2023-05-26 22:50:23 +00:00
aoo: utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]),
2022-08-16 09:29:15 +00:00
},
}
}