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

29 lines
829 B
JavaScript
Raw Normal View History

2022-08-16 09:29:15 +00:00
import Head from 'next/head';
import { readFile, set_fs, utils } from 'xlsx';
import { join } from 'path';
import { cwd } from 'process';
export default function Index({type, html}) { return ( <div>
<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>
2022-08-16 09:29:15 +00:00
This demo reads from /sheetjs.xlsx<br/><br/>
It generates HTML from the first sheet.<br/><br/>
2023-05-26 22:50:23 +00:00
</p>
<div dangerouslySetInnerHTML={{ __html: html }} />
2022-08-16 09:29:15 +00:00
</div> ); }
export async function getServerSideProps() {
set_fs(await import("fs"));
const wb = readFile(join(cwd(), "sheetjs.xlsx"))
return {
props: {
type: "getServerSideProps",
html: utils.sheet_to_html(wb.Sheets[wb.SheetNames[0]]),
},
}
}