Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 823317b

Browse files
committed
feat(ExcelExport): migrate to Excel-Builder-Vanilla (ESM)
1 parent ca4b39b commit 823317b

File tree

9 files changed

+165
-175
lines changed

9 files changed

+165
-175
lines changed

angular.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"allowedCommonJsDependencies": [
2222
"autocompleter",
2323
"dompurify",
24-
"excel-builder-webpacker",
2524
"fetch-jsonp",
2625
"flatpickr",
2726
"moment-mini",

docs/getting-started/quick-start.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ Then modify your `angular.json` file with the following Styles and Scripts:
4040
],
4141
```
4242

43-
#### if you use `@slickgrid-universal/excel-export` you need to update your `tsconfig.app.json`
44-
You need to change your `tsconfig.app.json` file to include `jszip` path (only required if you use the optional Slickgrid-Universal [Excel-Export](https://github.com/ghiscoding/slickgrid-universal/tree/master/packages/excel-export) package) by adding the following lines. If you forget to do this then your Angular Build will fail with a `jszip` error or `Sortable` error due to default exports that cannot be found. JSZip is used by the Excel Export to compress the data before downloading it and if you use it then the build seems to have problems finding the correct path of jszip unless we tell it where to find it.
45-
```js
46-
"compilerOptions": {
47-
// ...
48-
"allowSyntheticDefaultImports": true,
49-
"paths": {
50-
"jszip": ["../node_modules/jszip/dist/jszip.min.js"]
51-
}
52-
},
53-
```
54-
5543
<a name="step3"></a>
5644
### 3. CSS / SASS Styles
5745
Load the default Bootstrap theme style and/or customize it to your taste (either by using SASS or CSS variables)
@@ -222,10 +210,8 @@ You should also add `Angular-Slickgrid` and any dependency that Angular shows a
222210
"allowedCommonJsDependencies": [
223211
"autocompleter",
224212
"dompurify",
225-
"excel-builder-webpacker",
226213
"flatpickr",
227214
"moment-mini",
228-
"slickgrid",
229215
"stream"
230216
],
231217
}
@@ -258,10 +244,8 @@ This is no longer the case. Verify if you need this module and configure a polyf
258244
"allowedCommonJsDependencies": [
259245
"autocompleter",
260246
"dompurify",
261-
"excel-builder-webpacker",
262247
"fetch-jsonp",
263248
"flatpickr",
264-
"slickgrid",
265249
"stream"
266250
],
267251
],

docs/grid-functionalities/Export-to-Excel.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ You can Export to Excel, it will create an Excel file with the `.xlsx` default e
1919
### Demo
2020
[Demo Page](https://ghiscoding.github.io/Angular-Slickgrid/#/localization) / [Demo Component](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/examples/grid-localization.component.ts)
2121

22+
### CSP (Content Security Policy)
23+
Since we use the library `Excel-Builder-Vanilla`, which itself uses `fflate` as a dependency, that library uses Web Worker when it can which might throw a CSP error.
24+
25+
The easiest way to fix this problem is to modify your CSP header by adding the rule `worker-src 'self' blob:;`
26+
27+
```html
28+
<meta http-equiv="Content-Security-Policy"
29+
content="default-src 'self'; ...other rules... worker-src 'self' blob:;" />
30+
```
31+
2232
### Grid Menu (hamburger menu)
2333
The Grid Menu already has the "Export to Excel" enabled by default, so you will see it automatically in your Grid Menu. You still have the options to show/hide from the Grid Menu if you wish
2434
- `hideExportExcelCommand` false by default, so it's optional
@@ -136,7 +146,7 @@ this.gridOptions = {
136146
```
137147
138148
### Styling the Header Titles
139-
By default the header titles (first row) will be styled as Bold text, however you can choose to style them differently with custom styles as shown below. To find out what styling you can use, you can take a look [Web Archive - Excel Builder](http://web.archive.org/web/20160907052007/http://excelbuilderjs.com/cookbook/fontsAndColors.html) website. The code shown below is used in [Example 26](https://ghiscoding.github.io/Angular-Slickgrid/#/context) if you wish to see the result.
149+
By default the header titles (first row) will be styled as Bold text, however you can choose to style them differently with custom styles as shown below. To find out what styling you can use, you can take a look at Excel Builder-Vanilla [Documentation](https://ghiscoding.gitbook.io/excel-builder-vanilla/cookbook/fonts-and-colors) website. The code shown below is used in [Example 26](https://ghiscoding.github.io/Angular-Slickgrid/#/context) if you wish to see the result.
140150
141151
```ts
142152
this.gridOptions = {
@@ -150,7 +160,7 @@ this.gridOptions = {
150160
```
151161
152162
### Provide a Custom Header Title
153-
You can optionally add a custom header title, you can see the UI Sample below, (that will be shown on first row of the Excel file) through the `customExcelHeader` callback method. We use the library `Excel-Builder` to create the export, however note that this library is no longer supported (but still the best) and the documentation site no longer exist but you can find all info on [Web Archive - Excel Builder](http://web.archive.org/web/20160907052007/http://excelbuilderjs.com/cookbook/fontsAndColors.html)
163+
You can optionally add a custom header title, you can see the UI Sample below, (that will be shown on the first row of the Excel file) through the `customExcelHeader` callback method. We use the library `Excel-Builder-Vanilla` to create the export. Visit their [Documentation](https://ghiscoding.gitbook.io/excel-builder-vanilla/) website for more info.
154164
155165
The example below shows a title which uses a merged cell from "B1" to "D1" with a red bold color (pay attention to the color code, you need to add an extra "FF" in front of an html color code).
156166
#### ViewModel
@@ -163,8 +173,8 @@ export class MyExample {
163173
externalResources: [new ExcelExportService()],
164174
excelExportOptions: {
165175
// optionally pass a custom header to the Excel Sheet
166-
// a lot of the info can be found on Web Archive of Excel-Builder
167-
// http://web.archive.org/web/20160907052007/http://excelbuilderjs.com/cookbook/fontsAndColors.html
176+
// a lot of the info can be found on Excel-Builder-Vanilla
177+
// https://ghiscoding.gitbook.io/excel-builder-vanilla/cookbook/fonts-and-colors
168178
customExcelHeader: (workbook, sheet) => {
169179
const customTitle = this.translate.currentLang === 'fr' ? 'Titre qui est suffisament long pour être coupé' : 'My header that is long enough to wrap';
170180
const stylesheet = workbook.getStyleSheet();

docs/migrations/Migration-to-7.x.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ With this new major version release, we can now say that the journey to moderniz
1616
- TypeScript builds are now targeting ES2021 (bumped from ES2018)
1717
- more CSP (Content Security Policy) safe
1818
- you can create custom Formatter with native HTML element (to be more CSP safe), HTML strings are still accepted
19+
- migrate to [Excel-Builder-Vanilla](https://github.com/ghiscoding/excel-builder-vanilla) (since >=4.4.0)
20+
- for CSP safe, you also need to add `worker-src 'self' blob:;`
1921

2022
> **Note** for the full internal list of code changes applied in this Slickgrid-Universal release, you can take a look at the [Discussion - Roadmap to 4.0](https://github.com/ghiscoding/slickgrid-universal/discussions/1108)
2123
@@ -46,7 +48,7 @@ Since we moved all the code into the Slickgrid-Universal project and is now writ
4648
"allowedCommonJsDependencies": [
4749
"autocompleter",
4850
"dompurify",
49-
"excel-builder-webpacker",
51+
- "excel-builder-webpacker",
5052
"fetch-jsonp",
5153
"flatpickr",
5254
- "slickgrid",
@@ -58,6 +60,7 @@ Since we moved all the code into the Slickgrid-Universal project and is now writ
5860
- "node_modules/sortablejs/Sortable.min.js"
5961
],
6062
// ...
63+
}
6164
```
6265

6366
### Distribution folder
@@ -162,6 +165,27 @@ Some of the DomUtils Service function were renamed, if you use any of them then
162165
- `findFirstElementAttribute` renamed to `findFirstAttribute`
163166
- `htmlEncodedStringWithPadding` renamed to `htmlEncodeWithPadding`
164167

168+
### Excel Export
169+
_requires version >=7.4.0_
170+
171+
Migrate to a new [Excel-Builder-Vanilla](https://github.com/ghiscoding/excel-builder-vanilla) which is a fork of the `excel-builder.js` library. The new fork is all about modernizing Excel-Builder, it drops `Q`, `Lodash` and also replace `JSZip` to `fflate`.
172+
173+
By migrating from `JSZip` to `fflate`, the users should remove any `JSZip` references (like `tsconfig.json`)
174+
175+
```diff
176+
{
177+
"compilerOptions": {
178+
- "paths": {
179+
- "jszip": [
180+
- "node_modules/jszip/dist/jszip.min.js"
181+
- ]
182+
- }
183+
}
184+
}
185+
```
186+
187+
Also note that `fflate` could use Web Worker for performance reasons and by doing this you might have new CSP errors thrown. You simply need to add a CSP rule to avoid the error `worker-src 'self' blob:;`
188+
165189
## Formatters / CSP (Content Security Policy) Compliance
166190
### Formatters Cleanup & Removals
167191
I decided to remove a bunch of Formatters (like `Formatters.bold`, `Formatters.uppercase`, ...) because they could and should be using the column `cssClass` option. Basically, I did not myself use the best practice available when creating soo many Formatters and I did not realized that we could simply use `cssClass` which is a much more efficient way and so I'm correcting this inadvertence in this new release. With that in mind, I decided to do a big cleanup in the list of Formatters to make the project a little more lightweight with less code to support and replace some of them with more generic alternatives (see below).

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
},
5151
"dependencies": {
5252
"@ngx-translate/core": "^15.0.0",
53-
"@slickgrid-universal/common": "~4.3.1",
54-
"@slickgrid-universal/custom-footer-component": "~4.3.1",
55-
"@slickgrid-universal/empty-warning-component": "~4.3.1",
56-
"@slickgrid-universal/event-pub-sub": "~4.3.0",
57-
"@slickgrid-universal/pagination-component": "~4.3.1",
58-
"@slickgrid-universal/row-detail-view-plugin": "~4.3.1",
59-
"@slickgrid-universal/rxjs-observable": "~4.3.1",
53+
"@slickgrid-universal/common": "~4.4.0",
54+
"@slickgrid-universal/custom-footer-component": "~4.4.0",
55+
"@slickgrid-universal/empty-warning-component": "~4.4.0",
56+
"@slickgrid-universal/event-pub-sub": "~4.4.0",
57+
"@slickgrid-universal/pagination-component": "~4.4.0",
58+
"@slickgrid-universal/row-detail-view-plugin": "~4.4.0",
59+
"@slickgrid-universal/rxjs-observable": "~4.4.0",
6060
"dequal": "^2.0.3",
6161
"dompurify": "^3.0.8",
6262
"rxjs": "^7.8.1",
@@ -87,12 +87,12 @@
8787
"@ngx-translate/http-loader": "^8.0.0",
8888
"@popperjs/core": "^2.11.8",
8989
"@release-it/conventional-changelog": "^8.0.1",
90-
"@slickgrid-universal/composite-editor-component": "~4.3.1",
91-
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.1",
92-
"@slickgrid-universal/excel-export": "~4.3.1",
93-
"@slickgrid-universal/graphql": "~4.3.1",
94-
"@slickgrid-universal/odata": "~4.3.1",
95-
"@slickgrid-universal/text-export": "~4.3.1",
90+
"@slickgrid-universal/composite-editor-component": "~4.4.0",
91+
"@slickgrid-universal/custom-tooltip-plugin": "~4.4.0",
92+
"@slickgrid-universal/excel-export": "~4.4.0",
93+
"@slickgrid-universal/graphql": "~4.4.0",
94+
"@slickgrid-universal/odata": "~4.4.0",
95+
"@slickgrid-universal/text-export": "~4.4.0",
9696
"@types/dompurify": "^3.0.5",
9797
"@types/flatpickr": "^3.1.2",
9898
"@types/fnando__sparkline": "^0.3.7",

src/app/examples/grid-localization.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export class GridLocalizationComponent implements OnInit, OnDestroy {
169169
},
170170
excelExportOptions: {
171171
// optionally pass a custom header to the Excel Sheet
172-
// a lot of the info can be found on Web Archive of Excel-Builder
173-
// http://web.archive.org/web/20160907052007/http://excelbuilderjs.com/cookbook/fontsAndColors.html
172+
// a lot of the info can be found on Excel-Builder-Vanilla
173+
// https://ghiscoding.gitbook.io/excel-builder-vanilla/cookbook/fonts-and-colors
174174
customExcelHeader: (workbook, sheet) => {
175175
const customTitle = this.translate.currentLang === 'fr' ? 'Titre qui est suffisament long pour être coupé' : 'My header that is long enough to wrap';
176176
const stylesheet = workbook.getStyleSheet();

src/app/examples/grid-tree-data-hierarchical.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
22
import { ExcelExportService } from '@slickgrid-universal/excel-export';
33

44
import {
5+
addWhiteSpaces,
56
AngularGridInstance,
67
Aggregators,
78
Column,
@@ -259,19 +260,22 @@ export class GridTreeDataHierarchicalComponent implements OnInit {
259260
const identifierPropName = dataView.getIdPropertyName() || 'id';
260261
const idx = dataView.getIdxById(dataContext[identifierPropName]) as number;
261262
const prefix = this.getFileIcon(value);
263+
const treeLevel = dataContext[treeLevelPropName];
264+
const exportIndentationLeadingChar = '.';
262265

263266
value = value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
264-
const spacer = `<span style="display:inline-block; width:${(15 * dataContext[treeLevelPropName])}px;"></span>`;
267+
const spacer = `<span style="display:inline-block; width:${(15 * treeLevel)}px;"></span>`;
268+
const indentSpacer = addWhiteSpaces(5 * treeLevel);
265269

266270
if (data[idx + 1]?.[treeLevelPropName] > data[idx][treeLevelPropName] || data[idx]['__hasChildren']) {
267271
const folderPrefix = `<span class="mdi icon color-alt-warning ${dataContext.__collapsed ? 'mdi-folder' : 'mdi-folder-open'}"></span>`;
268272
if (dataContext.__collapsed) {
269-
return `${spacer} <span class="slick-group-toggle collapsed" level="${dataContext[treeLevelPropName]}"></span>${folderPrefix} ${prefix}&nbsp;${value}`;
273+
return `${exportIndentationLeadingChar}${spacer}${indentSpacer} <span class="slick-group-toggle collapsed" level="${treeLevel}"></span>${folderPrefix} ${prefix} ${value}`;
270274
} else {
271-
return `${spacer} <span class="slick-group-toggle expanded" level="${dataContext[treeLevelPropName]}"></span>${folderPrefix} ${prefix}&nbsp;${value}`;
275+
return `${exportIndentationLeadingChar}${spacer}${indentSpacer} <span class="slick-group-toggle expanded" level="${treeLevel}"></span>${folderPrefix} ${prefix} ${value}`;
272276
}
273277
} else {
274-
return `${spacer} <span class="slick-group-toggle" level="${dataContext[treeLevelPropName]}"></span>${prefix}&nbsp;${value}`;
278+
return `${exportIndentationLeadingChar}${spacer}${indentSpacer} <span class="slick-group-toggle" level="${treeLevel}"></span>${prefix} ${value}`;
275279
}
276280
};
277281

tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"module": "es2020",
2727
"baseUrl": "./",
2828
"paths": {
29-
"jszip": [
30-
"node_modules/jszip/dist/jszip.min.js"
31-
],
3229
"stream": [
3330
"./node_modules/stream-browserify"
3431
]

0 commit comments

Comments
 (0)