From cd61d177ddc2b5dea24635f25e875269a32877a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siemienik=20Pawe=C5=82?= Date: Sun, 12 Jan 2020 01:06:49 +0100 Subject: [PATCH 1/2] Readme.md v1 --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d092159 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/siemienik/xlsx-renderer)![GitHub top language](https://img.shields.io/github/languages/top/siemienik/xlsx-renderer)![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/siemienik/xlsx-renderer) + +# xlsx-renderer +Render xlsx from a template (it uses another xlsx file with special commands like "#! FOR_EACH item items") + +## In Cell Commands: + +1. `## varToDisplayInThisCell` +2. `#! FINISH` - finish processing current worksheet +2. `#! FINISH booleanVar` - if true it finishes processing current template worksheet, if false it add again this worksheet to output +3. `#! END_ROW` +4. `#! DELETE varName` +5. `#! HYPERLINK labelVar urlVar` +6. `#! WS_NAME nameVar` set worksheet name +7. `#! FOR_EACH item collection` (to write item property `## item.property`), +8. `#! CONTINUE item` item is set to the next collection item. +9. `#! END_LOOP item` +10. `#! AVERAGE item` write average formula of all items from previous for-each, it has to be placed after the for-each was finished. +11. `#! SUM item` similar to average +12. `#! DUMP_COLS arrayVar` write to next columns all array items (1 item = 1 column) From 80710510083bb3a0ca8d91c04bfd38227701ca10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Siemienik=20Pawe=C5=82?= Date: Sun, 12 Jan 2020 01:20:10 +0100 Subject: [PATCH 2/2] usage --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index d092159..b747bd8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,15 @@ # xlsx-renderer Render xlsx from a template (it uses another xlsx file with special commands like "#! FOR_EACH item items") +## Install: + +package.json: +``` + "xls-renderer": "git+ssh://git@github.com/siemienik/xlsx-renderer.git#release/v1", +``` + +`npm install` + ## In Cell Commands: 1. `## varToDisplayInThisCell` @@ -18,3 +27,32 @@ Render xlsx from a template (it uses another xlsx file with special commands lik 10. `#! AVERAGE item` write average formula of all items from previous for-each, it has to be placed after the for-each was finished. 11. `#! SUM item` similar to average 12. `#! DUMP_COLS arrayVar` write to next columns all array items (1 item = 1 column) + + +## Sample code: + +```javascript +import Renderer from './xls-renderer/Renderer' +import {Workbook} from 'exceljs' + +//* +import DebugCellTemplatePool from "./xls-renderer-debug/CellTemplateDebugPool"; +const renderer = new Renderer(new DebugCellTemplatePool()); +/*/ +import CellTemplatePool from "./xls-renderer/CellTemplatePool"; +const renderer = new Renderer(new CellTemplatePool()); +//*/ + + +const viewModel = new MyAwesomeReportVm(); //or something else + +(async () => { + const result = await renderer.render(async () => { + const template = new Workbook(); + return await template.xlsx.readFile('./my-awesome-raport-template.xlsx'); + }, viewModel); + + await result.xlsx.writeFile('./my-awesome-raport.xlsx'); +})(); + +```