xsheetjs/demos/xspreadsheet/README.md

67 lines
1.8 KiB
Markdown
Raw Normal View History

2020-03-23 01:57:53 +00:00
# x-spreadsheet
The `sheet_to_json` utility function generates output arrays suitable for use
with other JS libraries such as data grids for previewing data. With a familiar
UI, [`x-spreadsheet`](https://myliang.github.io/x-spreadsheet/) is an excellent
choice for developers looking for a modern editor.
This demo is available at <https://oss.sheetjs.com/sheetjs/x-spreadsheet.html>
## Obtaining the Library
2022-05-17 21:48:05 +00:00
The `x-data-spreadsheet` NodeJS packages include a minified script that can be
2022-05-20 08:56:18 +00:00
directly inserted as a script tag. The unpkg CDN also serves this script:
2020-03-23 01:57:53 +00:00
```html
<script src="https://unpkg.com/x-data-spreadsheet/dist/xspreadsheet.js"></script>
```
## Previewing Data
The HTML document needs a container element:
```html
<div id="gridctr"></div>
```
Grid initialization is a one-liner:
```js
/* note that the browser build exposes the variable `x` */
2021-09-12 05:58:37 +00:00
var grid = x_spreadsheet(document.getElementById("gridctr"));
2020-03-23 01:57:53 +00:00
```
The following function converts data from SheetJS to x-spreadsheet:
```js
/* load data */
grid.loadData(stox(workbook_object));
```
2021-10-13 07:20:25 +00:00
`stox` is defined in [`xlsxspread.js`](./xlsxspread.js)
2020-03-23 01:57:53 +00:00
## Editing
`x-spreadsheet` handles the entire edit cycle. No intervention is necessary.
2020-03-23 01:57:53 +00:00
## Saving Data
`grid.getData()` returns an object that can be converted back to a worksheet:
```js
/* build workbook from the grid data */
var new_wb = xtos(xspr.getData());
/* generate download */
XLSX.writeFile(new_wb, "SheetJS.xlsx");
```
2021-10-13 07:20:25 +00:00
`stox` is defined in [`xlsxspread.js`](./xlsxspread.js)
2020-03-23 01:57:53 +00:00
## Additional Features
This demo barely scratches the surface. The underlying grid component includes
many additional features that work with [SheetJS Pro](https://sheetjs.com/pro).
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)