Skip to content

Commit

Permalink
Update browser support (xlsx-renderer / README.md)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siemienik authored Mar 13, 2021
1 parent d62cb93 commit 038475e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/xlsx-renderer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,32 @@ If Node v8 & v9 needed, please contact us [[email protected]](mailto://suppor

### ✅ Browser Support

XLSX Renderer may run on browser side, [read more how to do it](https://github.com/Siemienik/XToolSet/issues/93).
XLSX Renderer may run on browser side. [**Read more about browser support**](https://github.com/Siemienik/XToolset/issues/93#issuecomment-797835786).

```js
import { Renderer } from "xlsx-renderer";
import { saveAs } from "file-saver";

// ... define viewModel:
const viewModel = {};

//... generate a report:

// 1. Download a template.
fetch("./template.xlsx")
// 2. Get template as ArrayBuffer.
.then((response) => response.arrayBuffer())
// 3. Fill the template with data (generate a report).
.then((buffer) => new Renderer().renderFromArrayBuffer(buffer, viewModel))
// 4. Get a report as buffer.
.then((report) => report.xlsx.writeBuffer())
// 5. Use `saveAs` to download on browser site.
.then((buffer) => saveAs(new Blob([buffer]), `${Date.now()}_report.xlsx`))
// Handle errors.
.catch((err) => console.log("Error writing excel export", err));
```

[**Read more about browser support**](https://github.com/Siemienik/XToolset/issues/93#issuecomment-797835786).

---

Expand Down

0 comments on commit 038475e

Please sign in to comment.