forked from sheetjs/docs.sheetjs.com
Compare commits
No commits in common. "master" and "demo-postgresql-improved-type-detection" have entirely different histories.
master
...
demo-postg
@ -277,24 +277,27 @@ This complete component example fetches a test file and displays the contents in
|
||||
a HTML table. When the export button is clicked, a callback will export a file:
|
||||
|
||||
```jsx title="src/SheetJSReactAoO.js"
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { read, utils, writeFileXLSX } from 'xlsx';
|
||||
|
||||
export default function SheetJSReactAoO() {
|
||||
/* the component state is an array of presidents */
|
||||
const [pres, setPres] = useState([] /* as any[] */);
|
||||
const [pres, setPres] = useState([]);
|
||||
|
||||
/* Fetch and update the state once */
|
||||
useEffect(() => { (async() => {
|
||||
const f = await (await fetch("https://docs.sheetjs.com/pres.xlsx")).arrayBuffer();
|
||||
// highlight-start
|
||||
const wb = read(f); // parse the array buffer
|
||||
const ws = wb.Sheets[wb.SheetNames[0]]; // get the first worksheet
|
||||
const data = utils.sheet_to_json(ws); // generate objects
|
||||
setPres(data); // update state
|
||||
// highlight-end
|
||||
})(); }, []);
|
||||
|
||||
/* get state data and export to XLSX */
|
||||
const exportFile = useCallback(() => {
|
||||
// highlight-next-line
|
||||
const ws = utils.json_to_sheet(pres);
|
||||
const wb = utils.book_new();
|
||||
utils.book_append_sheet(wb, ws, "Data");
|
||||
@ -303,14 +306,16 @@ export default function SheetJSReactAoO() {
|
||||
|
||||
return (<table><thead><tr><th>Name</th><th>Index</th></tr></thead><tbody>
|
||||
{ /* generate row for each president */
|
||||
pres.map((pres, index) => (<tr key={index}>
|
||||
// highlight-start
|
||||
pres.map(pres => (<tr>
|
||||
<td>{pres.Name}</td>
|
||||
<td>{pres.Index}</td>
|
||||
</tr>))
|
||||
// highlight-end
|
||||
}
|
||||
</tbody><tfoot><tr><td colSpan={2}>
|
||||
</tbody><tfoot><td colSpan={2}>
|
||||
<button onClick={exportFile}>Export XLSX</button>
|
||||
</td></tr></tfoot></table>);
|
||||
</td></tfoot></table>);
|
||||
}
|
||||
```
|
||||
|
||||
@ -326,7 +331,7 @@ This demo was tested in the following environments:
|
||||
|
||||
| ReactJS | ViteJS | Date |
|
||||
|:---------|:--------|:-----------|
|
||||
| `18.3.1` | `6.0.1` | 2024-12-12 |
|
||||
| `18.2.0` | `5.1.6` | 2024-03-13 |
|
||||
|
||||
:::
|
||||
|
||||
@ -358,7 +363,7 @@ and the page will attempt to download `SheetJSReactAoO.xlsx`.
|
||||
npm run build
|
||||
```
|
||||
|
||||
The generated site will be placed in the `.next` folder.
|
||||
The generated site will be placed in the `dist` folder.
|
||||
|
||||
6) Start a local web server:
|
||||
|
||||
@ -378,17 +383,10 @@ This demo was tested in the following environments:
|
||||
|
||||
| ReactJS | CRA | Date |
|
||||
|:---------|:--------|:-----------|
|
||||
| `18.2.0` | `5.0.1` | 2024-12-12 |
|
||||
| `18.2.0` | `5.0.1` | 2024-03-13 |
|
||||
|
||||
:::
|
||||
|
||||
:::caution
|
||||
|
||||
CRA has known compatibility issues with React 19+[^cra]. CRA no longer receives updates and the ReactJS docs no longer recommend using CRA. For new projects, it is strongly recommended to use ViteJS with the react or react-ts templates.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
1) Create a new site:
|
||||
|
||||
```bash
|
||||
@ -400,7 +398,6 @@ npx -y create-react-app@5.0.1 --scripts-version=5.0.1 sheetjs-react
|
||||
<CodeBlock language="bash">{`\
|
||||
cd sheetjs-react
|
||||
npm i
|
||||
npm i react@18.2.0 react-dom@18.2.0 web-vitals --save --save-exact # fixes CRA dependency conflicts w/ React 19
|
||||
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz
|
||||
npm start`}
|
||||
</CodeBlock>
|
||||
@ -429,8 +426,6 @@ npx http-server build
|
||||
Access the displayed URL (typically `http://localhost:8080`) with a web browser
|
||||
and test the page.
|
||||
|
||||
[^cra]: See [Create React App Issue #13717](https://github.com/facebook/create-react-app/issues/13717) for details about React 19+ compatibility issues.
|
||||
|
||||
</TabItem>
|
||||
<TabItem name="nextjs" value="NextJS">
|
||||
|
||||
@ -440,7 +435,7 @@ This demo was tested in the following environments:
|
||||
|
||||
| ReactJS | NextJS | Date |
|
||||
|:---------|:---------|:-----------|
|
||||
| `19.0.0` | `15.1.0` | 2024-12-13 |
|
||||
| `18.2.0` | `14.1.3` | 2024-03-13 |
|
||||
|
||||
:::
|
||||
|
||||
@ -485,26 +480,26 @@ npx next telemetry disable
|
||||
1) Create a new site:
|
||||
|
||||
```bash
|
||||
npx create-next-app@latest sheetjs-nextjs --ts --no-eslint --no-tailwind --no-src-dir --no-app --import-alias "@/*" --no-turbopack
|
||||
npx create-next-app@latest sheetjs-react --ts --no-eslint --no-tailwind --no-src-dir --no-app --import-alias "@/*"
|
||||
```
|
||||
|
||||
2) Install the SheetJS dependency and start the dev server:
|
||||
|
||||
<CodeBlock language="bash">{`\
|
||||
cd sheetjs-nextjs
|
||||
cd sheetjs-react
|
||||
npm i
|
||||
npx next telemetry disable
|
||||
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz
|
||||
npm run dev`}
|
||||
</CodeBlock>
|
||||
|
||||
3) Open a web browser and access the displayed URL (`http://localhost:3000`)
|
||||
3) Open a web browser and access the displayed URL (`http://localhost:5173`)
|
||||
|
||||
4) Replace `pages/index.tsx` with the `src/SheetJSReactAoO.js` example.
|
||||
4) Replace `src/App.jsx` with the `src/SheetJSReactAoO.js` example.
|
||||
|
||||
After replacing the code, add the following to the top of `pages/index.tsx`:
|
||||
After replacing the code, add the following to the top of `src/App.jsx`:
|
||||
|
||||
```js title="src/index.tsx (add to top)"
|
||||
```js title="src/App.jsx (add to top)"
|
||||
"use client";
|
||||
```
|
||||
|
||||
@ -540,7 +535,7 @@ The generated site will be placed in the `dist` folder.
|
||||
6) Start a local web server:
|
||||
|
||||
```bash
|
||||
npm run start
|
||||
npx http-server dist
|
||||
```
|
||||
|
||||
Access the displayed URL (typically `http://localhost:8080`) with a web browser
|
||||
@ -571,7 +566,7 @@ export, the first `TABLE` child element can be parsed with [`table_to_book`](/do
|
||||
generate a workbook object.
|
||||
|
||||
```jsx title="src/SheetJSReactHTML.js"
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { read, utils, writeFileXLSX } from 'xlsx';
|
||||
|
||||
export default function SheetJSReactHTML() {
|
||||
@ -620,7 +615,7 @@ This demo was tested in the following environments:
|
||||
|
||||
| ReactJS | ViteJS | Date |
|
||||
|:---------|:--------|:-----------|
|
||||
| `18.3.1` | `6.0.1` | 2024-12-13 |
|
||||
| `18.2.0` | `5.1.6` | 2024-03-13 |
|
||||
|
||||
:::
|
||||
|
||||
@ -676,12 +671,6 @@ This demo was tested in the following environments:
|
||||
|
||||
:::
|
||||
|
||||
:::caution
|
||||
|
||||
CRA has known compatibility issues with React 19+[^cra]. CRA no longer receives updates and the ReactJS docs no longer recommend using CRA. For new projects, it is strongly recommended to use ViteJS with the react or react-ts templates.
|
||||
|
||||
:::
|
||||
|
||||
1) Create a new site:
|
||||
|
||||
```bash
|
||||
@ -693,7 +682,6 @@ npx -y create-react-app@5.0.1 --scripts-version=5.0.1 sheetjs-react
|
||||
<CodeBlock language="bash">{`\
|
||||
cd sheetjs-react
|
||||
npm i
|
||||
npm i react@18.2.0 react-dom@18.2.0 web-vitals --save --save-exact # fixes CRA dependency conflicts w/ React 19
|
||||
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz
|
||||
npm start`}
|
||||
</CodeBlock>
|
||||
|
@ -24,10 +24,10 @@ This demo was verified by NetSuite consultants in the following deployments:
|
||||
|
||||
| `@NScriptType` | `@NApiVersion` | Date |
|
||||
|:----------------|:---------------|:-----------|
|
||||
| ScheduledScript | 2.1 | 2024-12-06 |
|
||||
| Restlet | 2.1 | 2024-12-06 |
|
||||
| Suitelet | 2.1 | 2024-12-06 |
|
||||
| MapReduceScript | 2.1 | 2024-12-06 |
|
||||
| ScheduledScript | 2.1 | 2024-05-01 |
|
||||
| Restlet | 2.1 | 2024-05-01 |
|
||||
| Suitelet | 2.1 | 2024-05-01 |
|
||||
| MapReduceScript | 2.1 | 2024-05-01 |
|
||||
|
||||
:::
|
||||
|
||||
@ -66,23 +66,17 @@ It is strongly recommended to keep the original filename `xlsx.full.min.js`.
|
||||
#### JSON Configuration
|
||||
|
||||
Assuming the uploaded file was named `xlsx.full.min.js`, the `paths` object in
|
||||
the JSON configuration should reference `xlsx.full.min.js`. The reference can be
|
||||
the JSON configuration should reference `xlsx.full.min`. The reference can be
|
||||
absolute or relative[^4].
|
||||
|
||||
:::note pass
|
||||
|
||||
On older versions of SuiteScript, you might need to use without `.js` extension.
|
||||
|
||||
:::
|
||||
|
||||
For example, if the script `xlsx.full.min.js` was placed in the `SuiteScripts`
|
||||
top-level directory, the config should use `"/SuiteScripts/xlsx.full.min.js"`:
|
||||
top-level directory, the config should use `"/SuiteScripts/xlsx.full.min"`:
|
||||
|
||||
```json title="JsLibraryConfig.json"
|
||||
{
|
||||
"paths": {
|
||||
// highlight-next-line
|
||||
"xlsx": "/SuiteScripts/xlsx.full.min.js"
|
||||
"xlsx": "/SuiteScripts/xlsx.full.min"
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -94,7 +88,7 @@ folder, the config can use `"./xlsx.full.min"`:
|
||||
{
|
||||
"paths": {
|
||||
// highlight-next-line
|
||||
"xlsx": "./xlsx.full.min.js"
|
||||
"xlsx": "./xlsx.full.min"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user