-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update browser support (xlsx-renderer / README.md)
ref: #93 (comment)
- Loading branch information
Showing
1 changed file
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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). | ||
|
||
--- | ||
|
||
|