-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ReactJS demo for js-xlsx is very unclear to me #1172
Comments
If the demo doesn't make sense, we probably are missing something. Here's a longer explanation. If this makes sense, please let us know how to improve the README: To run the demo, clone the repo and go to that subdirectory ( You should see something like: Then select a spreadsheet by clicking the file input button or dragging and dropping a file like If you add the line That object represents the state that the example uses. https://github.com/SheetJS/js-xlsx/blob/master/demos/react/sheetjs.jsx is the demo component used in the web examples.
/* convert state.data to worksheet */
const ws = XLSX.utils.aoa_to_sheet(this.state.data);
/* build a workbook */
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "SheetJS");
/* generate XLSX file and send to client */
XLSX.writeFile(wb, "sheetjs.xlsx") The callback is triggered when a certain button is clicked: <button disabled={!this.state.data.length} className="btn btn-success" onClick={this.exportFile}>Export</button> On the read side, the state is set when you process a file. If that explanation makes sense, please feel free to submit a PR to clarify the README. |
I understand now and I think your answer is very clear! |
react ant design you can try to see |
hello, i am here trying as well cloning the repo and building react demo, but after i run mkdir -p node_modules
cd node_modules; if [ ! -e xlsx ]; then ln -s ../../../ xlsx; fi; cd -
<REDACTED>/SheetJS/demos/react
python -mSimpleHTTPServer
make: python: No such file or directory
make: *** [react] Error 1 anything that i forgot after i cloned the repo and did |
There is a plan to redo the demo and make it more interactive (like https://docs.sheetjs.com/docs/#export-an-html-table-to-excel-xlsx on the docs page). For now, replace the python line with
It will start a server on port 8080. You can open http://localhost:8080 in your web browser Note that the |
i did modify this file
everything then works. |
The React demos have been revisited: https://docs.sheetjs.com/docs/demos/react is a general discussion of different internal states you can use in React apps. Each approach has a dedicated example which can be added to a CRA or Vite+React app. The old example is preserved in the "Legacy" section. https://docs.sheetjs.com/docs/demos/grid#react-data-grid is an example where https://docs.sheetjs.com/docs/demos/mobile#react-native is the new React Native example covering a number of Filesystem and File Picker plugins https://docs.sheetjs.com/docs/demos/content/#nextjs covers NextJS and static generation For desktop apps we wanted to showcase react-native-windows (the Tauri demo uses Vue) but there are a few showstoppers like microsoft/react-native-windows#10059 |
EDIT: https://docs.sheetjs.com/docs/demos/frontend/react/ is the primary demo. It discusses state representations and links to React ecosystem demos including static site generation, data grids, and native desktop and mobile apps
Sorry if I am not skilled enough to understand the demo,
but this page: https://github.com/SheetJS/js-xlsx/tree/master/demos/react
is very unclear to me and I still don't get how this library has to be used in ReactJS.
How do we have to use this object
and download it as a xlsx? Please help!
The text was updated successfully, but these errors were encountered: