@delon/abc 12.2.3 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/bundles/abc.umd.js +1 -1
  2. package/bundles/autoFocus.umd.js +1 -1
  3. package/bundles/avatarList.umd.js +1 -1
  4. package/bundles/count-down.umd.js +1 -1
  5. package/bundles/datePicker.umd.js +1 -1
  6. package/bundles/downFile.umd.js +1 -1
  7. package/bundles/edit.umd.js +1 -1
  8. package/bundles/ellipsis.umd.js +1 -1
  9. package/bundles/errorCollect.umd.js +1 -1
  10. package/bundles/exception.umd.js +1 -1
  11. package/bundles/footerToolbar.umd.js +1 -1
  12. package/bundles/fullContent.umd.js +1 -1
  13. package/bundles/globalFooter.umd.js +1 -1
  14. package/bundles/grid.umd.js +1 -1
  15. package/bundles/image.umd.js +1 -1
  16. package/bundles/let.umd.js +1 -1
  17. package/bundles/loading.umd.js +1 -1
  18. package/bundles/lodop.umd.js +1 -1
  19. package/bundles/media.umd.js +1 -1
  20. package/bundles/noticeIcon.umd.js +1 -1
  21. package/bundles/onboarding.umd.js +1 -1
  22. package/bundles/pageHeader.umd.js +1 -1
  23. package/bundles/pdf.umd.js +1 -1
  24. package/bundles/qr.umd.js +1 -1
  25. package/bundles/quickMenu.umd.js +1 -1
  26. package/bundles/result.umd.js +1 -1
  27. package/bundles/reuseTab.umd.js +1 -1
  28. package/bundles/table.umd.js +4 -1
  29. package/bundles/table.umd.js.map +1 -1
  30. package/bundles/tagSelect.umd.js +1 -1
  31. package/bundles/view.umd.js +1 -1
  32. package/bundles/xlsx.umd.js +27 -32
  33. package/bundles/xlsx.umd.js.map +1 -1
  34. package/bundles/zip.umd.js +1 -1
  35. package/esm2015/st/st-column-source.js +4 -1
  36. package/esm2015/xlsx/xlsx.service.js +23 -29
  37. package/esm2015/xlsx/xlsx.types.js +1 -1
  38. package/fesm2015/table.js +3 -0
  39. package/fesm2015/table.js.map +1 -1
  40. package/fesm2015/xlsx.js +22 -28
  41. package/fesm2015/xlsx.js.map +1 -1
  42. package/package.json +4 -4
  43. package/xlsx/xlsx.metadata.json +1 -1
  44. package/xlsx/xlsx.types.d.ts +3 -0
package/fesm2015/xlsx.js CHANGED
@@ -3,7 +3,6 @@ import * as i1 from '@angular/common/http';
3
3
  import { HttpClient } from '@angular/common/http';
4
4
  import * as i0 from '@angular/core';
5
5
  import { Injectable, NgZone, Directive, Input, NgModule } from '@angular/core';
6
- import { saveAs } from 'file-saver';
7
6
  import isUtf8 from 'isutf8';
8
7
  import * as i3 from '@delon/util/config';
9
8
  import { AlainConfigService } from '@delon/util/config';
@@ -27,24 +26,22 @@ class XlsxService {
27
26
  ? Promise.resolve([])
28
27
  : this.lazy.load([this.cog.url].concat(this.cog.modules));
29
28
  }
30
- read(data, options) {
29
+ read(data) {
30
+ const { read, utils: { sheet_to_json } } = XLSX;
31
31
  const ret = {};
32
- if (options.type === 'binary') {
33
- const buf = new Uint8Array(data);
34
- if (!isUtf8(buf)) {
35
- try {
36
- data = cptable.utils.decode(936, buf);
37
- options.type = 'string';
38
- }
39
- catch (_a) {
40
- options.type = 'array';
41
- }
32
+ const buf = new Uint8Array(data);
33
+ let type = 'array';
34
+ if (!isUtf8(buf)) {
35
+ try {
36
+ data = cptable.utils.decode(936, buf);
37
+ type = 'string';
42
38
  }
39
+ catch (_a) { }
43
40
  }
44
- const wb = XLSX.read(data, options);
41
+ const wb = read(data, { type });
45
42
  wb.SheetNames.forEach((name) => {
46
43
  const sheet = wb.Sheets[name];
47
- ret[name] = XLSX.utils.sheet_to_json(sheet, { header: 1 });
44
+ ret[name] = sheet_to_json(sheet, { header: 1 });
48
45
  });
49
46
  return ret;
50
47
  }
@@ -53,22 +50,18 @@ class XlsxService {
53
50
  */
54
51
  import(fileOrUrl) {
55
52
  return new Promise((resolve, reject) => {
53
+ const r = (data) => this.ngZone.run(() => resolve(this.read(data)));
56
54
  this.init()
57
55
  .then(() => {
58
56
  // from url
59
57
  if (typeof fileOrUrl === 'string') {
60
- this.http.request('GET', fileOrUrl, { responseType: 'arraybuffer' }).subscribe((res) => {
61
- this.ngZone.run(() => resolve(this.read(new Uint8Array(res), { type: 'array' })));
62
- }, (err) => {
63
- reject(err);
64
- });
58
+ this.http.request('GET', fileOrUrl, { responseType: 'arraybuffer' }).subscribe((res) => r(new Uint8Array(res)), (err) => reject(err));
65
59
  return;
66
60
  }
67
61
  // from file
68
62
  const reader = new FileReader();
69
- reader.onload = (e) => {
70
- this.ngZone.run(() => resolve(this.read(e.target.result, { type: 'binary' })));
71
- };
63
+ reader.onload = (e) => r(e.target.result);
64
+ reader.onerror = (e) => reject(e);
72
65
  reader.readAsArrayBuffer(fileOrUrl);
73
66
  })
74
67
  .catch(() => reject(`Unable to load xlsx.js`));
@@ -79,11 +72,13 @@ class XlsxService {
79
72
  return new Promise((resolve, reject) => {
80
73
  this.init()
81
74
  .then(() => {
82
- const wb = XLSX.utils.book_new();
75
+ options = Object.assign({ format: 'xlsx' }, options);
76
+ const { writeFile, utils: { book_new, aoa_to_sheet, book_append_sheet } } = XLSX;
77
+ const wb = book_new();
83
78
  if (Array.isArray(options.sheets)) {
84
79
  options.sheets.forEach((value, index) => {
85
- const ws = XLSX.utils.aoa_to_sheet(value.data);
86
- XLSX.utils.book_append_sheet(wb, ws, value.name || `Sheet${index + 1}`);
80
+ const ws = aoa_to_sheet(value.data);
81
+ book_append_sheet(wb, ws, value.name || `Sheet${index + 1}`);
87
82
  });
88
83
  }
89
84
  else {
@@ -92,9 +87,8 @@ class XlsxService {
92
87
  }
93
88
  if (options.callback)
94
89
  options.callback(wb);
95
- const wbout = XLSX.write(wb, Object.assign({ bookType: 'xlsx', bookSST: false, type: 'array' }, options.opts));
96
- const filename = options.filename || 'export.xlsx';
97
- saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
90
+ const filename = options.filename || `export.${options.format}`;
91
+ writeFile(wb, filename, Object.assign({ bookType: options.format, bookSST: false, type: 'array' }, options.opts));
98
92
  resolve({ filename, wb });
99
93
  })
100
94
  .catch(err => reject(err));
@@ -1 +1 @@
1
- {"version":3,"file":"xlsx.js","sources":["../../../../packages/abc/xlsx/xlsx.service.ts","../../../../packages/abc/xlsx/xlsx.directive.ts","../../../../packages/abc/xlsx/xlsx.module.ts","../../../../packages/abc/xlsx/xlsx.ts"],"sourcesContent":["import { HttpClient } from '@angular/common/http';\nimport { Injectable, NgZone } from '@angular/core';\n\nimport { saveAs } from 'file-saver';\nimport isUtf8 from 'isutf8';\n\nimport { AlainConfigService, AlainXlsxConfig } from '@delon/util/config';\nimport { ZoneOutside } from '@delon/util/decorator';\nimport { LazyResult, LazyService } from '@delon/util/other';\nimport type { NzSafeAny } from 'ng-zorro-antd/core/types';\n\nimport { XlsxExportOptions, XlsxExportResult, XlsxExportSheet } from './xlsx.types';\n\ndeclare var XLSX: NzSafeAny;\ndeclare var cptable: NzSafeAny;\n\n@Injectable({ providedIn: 'root' })\nexport class XlsxService {\n constructor(\n private http: HttpClient,\n private lazy: LazyService,\n configSrv: AlainConfigService,\n private ngZone: NgZone\n ) {\n this.cog = configSrv.merge('xlsx', {\n url: 'https://cdn.bootcdn.net/ajax/libs/xlsx/0.16.8/xlsx.full.min.js',\n modules: [`https://cdn.bootcdn.net/ajax/libs/xlsx/0.16.8/cpexcel.min.js`]\n })!;\n }\n private cog: AlainXlsxConfig;\n\n private init(): Promise<LazyResult[]> {\n return typeof XLSX !== 'undefined'\n ? Promise.resolve([])\n : this.lazy.load([this.cog.url!].concat(this.cog.modules!));\n }\n\n @ZoneOutside()\n private read(data: NzSafeAny, options: { type: 'array' | 'binary' | 'string' }): { [key: string]: NzSafeAny[][] } {\n const ret: NzSafeAny = {};\n if (options.type === 'binary') {\n const buf = new Uint8Array(data);\n if (!isUtf8(buf)) {\n try {\n data = cptable.utils.decode(936, buf);\n options.type = 'string';\n } catch {\n options.type = 'array';\n }\n }\n }\n const wb = XLSX.read(data, options);\n wb.SheetNames.forEach((name: string) => {\n const sheet: NzSafeAny = wb.Sheets[name];\n ret[name] = XLSX.utils.sheet_to_json(sheet, { header: 1 });\n });\n return ret;\n }\n\n /**\n * 导入Excel并输出JSON,支持 `<input type=\"file\">`、URL 形式\n */\n import(fileOrUrl: File | string): Promise<{ [key: string]: NzSafeAny[][] }> {\n return new Promise<{ [key: string]: NzSafeAny[][] }>((resolve, reject) => {\n this.init()\n .then(() => {\n // from url\n if (typeof fileOrUrl === 'string') {\n this.http.request('GET', fileOrUrl, { responseType: 'arraybuffer' }).subscribe(\n (res: ArrayBuffer) => {\n this.ngZone.run(() => resolve(this.read(new Uint8Array(res), { type: 'array' })));\n },\n (err: NzSafeAny) => {\n reject(err);\n }\n );\n return;\n }\n // from file\n const reader: FileReader = new FileReader();\n reader.onload = (e: NzSafeAny) => {\n this.ngZone.run(() => resolve(this.read(e.target.result, { type: 'binary' })));\n };\n reader.readAsArrayBuffer(fileOrUrl);\n })\n .catch(() => reject(`Unable to load xlsx.js`));\n });\n }\n\n @ZoneOutside()\n async export(options: XlsxExportOptions): Promise<XlsxExportResult> {\n return new Promise<XlsxExportResult>((resolve, reject) => {\n this.init()\n .then(() => {\n const wb: NzSafeAny = XLSX.utils.book_new();\n if (Array.isArray(options.sheets)) {\n (options.sheets as XlsxExportSheet[]).forEach((value: XlsxExportSheet, index: number) => {\n const ws: NzSafeAny = XLSX.utils.aoa_to_sheet(value.data);\n XLSX.utils.book_append_sheet(wb, ws, value.name || `Sheet${index + 1}`);\n });\n } else {\n wb.SheetNames = Object.keys(options.sheets);\n wb.Sheets = options.sheets;\n }\n\n if (options.callback) options.callback(wb);\n\n const wbout: ArrayBuffer = XLSX.write(wb, {\n bookType: 'xlsx',\n bookSST: false,\n type: 'array',\n ...options.opts\n });\n const filename = options.filename || 'export.xlsx';\n saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);\n\n resolve({ filename, wb });\n })\n .catch(err => reject(err));\n });\n }\n\n /**\n * 数据转符号名\n * - `1` => `A`\n * - `27` => `AA`\n * - `703` => `AAA`\n */\n numberToSchema(val: number): string {\n const startCode = 'A'.charCodeAt(0);\n let res = '';\n\n do {\n --val;\n res = String.fromCharCode(startCode + (val % 26)) + res;\n val = (val / 26) >> 0;\n } while (val > 0);\n\n return res;\n }\n}\n","import { Directive, Input } from '@angular/core';\n\nimport { XlsxService } from './xlsx.service';\nimport { XlsxExportOptions } from './xlsx.types';\n\n@Directive({\n selector: '[xlsx]',\n exportAs: 'xlsx',\n host: {\n '(click)': '_click()'\n }\n})\nexport class XlsxDirective {\n @Input('xlsx') data: XlsxExportOptions;\n\n constructor(private srv: XlsxService) {}\n\n _click(): void {\n this.srv.export(this.data);\n }\n}\n","import { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\n\nimport { XlsxDirective } from './xlsx.directive';\n\nconst COMPONENTS = [XlsxDirective];\n\n@NgModule({\n imports: [CommonModule],\n declarations: COMPONENTS,\n exports: COMPONENTS\n})\nexport class XlsxModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;MAiBa,WAAW;IACtB,YACU,IAAgB,EAChB,IAAiB,EACzB,SAA6B,EACrB,MAAc;QAHd,SAAI,GAAJ,IAAI,CAAY;QAChB,SAAI,GAAJ,IAAI,CAAa;QAEjB,WAAM,GAAN,MAAM,CAAQ;QAEtB,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE;YACjC,GAAG,EAAE,gEAAgE;YACrE,OAAO,EAAE,CAAC,8DAA8D,CAAC;SAC1E,CAAE,CAAC;KACL;IAGO,IAAI;QACV,OAAO,OAAO,IAAI,KAAK,WAAW;cAC9B,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;cACnB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAQ,CAAC,CA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E,WAAW;YAFvB,kBAAkB;YALN,MAAM;;AAqCzB;IADC,WAAW,EAAE;uCAoBb;AAiCD;IADC,WAAW,EAAE;yCA+Bb;;MC5GU,aAAa;IAGxB,YAAoB,GAAgB;QAAhB,QAAG,GAAH,GAAG,CAAa;KAAI;IAExC,MAAM;QACJ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B;;;YAdF,SAAS,SAAC;gBACT,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,MAAM;gBAChB,IAAI,EAAE;oBACJ,SAAS,EAAE,UAAU;iBACtB;aACF;;;YATQ,WAAW;;;mBAWjB,KAAK,SAAC,MAAM;;;ACRf,MAAM,UAAU,GAAG,CAAC,aAAa,CAAC,CAAC;MAOtB,UAAU;;;YALtB,QAAQ,SAAC;gBACR,OAAO,EAAE,CAAC,YAAY,CAAC;gBACvB,YAAY,EAAE,UAAU;gBACxB,OAAO,EAAE,UAAU;aACpB;;;ACXD;;;;;;"}
1
+ {"version":3,"file":"xlsx.js","sources":["../../../../packages/abc/xlsx/xlsx.service.ts","../../../../packages/abc/xlsx/xlsx.directive.ts","../../../../packages/abc/xlsx/xlsx.module.ts","../../../../packages/abc/xlsx/xlsx.ts"],"sourcesContent":["import { HttpClient } from '@angular/common/http';\nimport { Injectable, NgZone } from '@angular/core';\n\nimport isUtf8 from 'isutf8';\n\nimport { AlainConfigService, AlainXlsxConfig } from '@delon/util/config';\nimport { ZoneOutside } from '@delon/util/decorator';\nimport { LazyResult, LazyService } from '@delon/util/other';\nimport type { NzSafeAny } from 'ng-zorro-antd/core/types';\n\nimport { XlsxExportOptions, XlsxExportResult, XlsxExportSheet } from './xlsx.types';\n\ndeclare var XLSX: NzSafeAny;\ndeclare var cptable: NzSafeAny;\n\n@Injectable({ providedIn: 'root' })\nexport class XlsxService {\n constructor(\n private http: HttpClient,\n private lazy: LazyService,\n configSrv: AlainConfigService,\n private ngZone: NgZone\n ) {\n this.cog = configSrv.merge('xlsx', {\n url: 'https://cdn.bootcdn.net/ajax/libs/xlsx/0.16.8/xlsx.full.min.js',\n modules: [`https://cdn.bootcdn.net/ajax/libs/xlsx/0.16.8/cpexcel.min.js`]\n })!;\n }\n private cog: AlainXlsxConfig;\n\n private init(): Promise<LazyResult[]> {\n return typeof XLSX !== 'undefined'\n ? Promise.resolve([])\n : this.lazy.load([this.cog.url!].concat(this.cog.modules!));\n }\n\n @ZoneOutside()\n private read(data: NzSafeAny): { [key: string]: NzSafeAny[][] } {\n const {\n read,\n utils: { sheet_to_json }\n } = XLSX;\n const ret: NzSafeAny = {};\n const buf = new Uint8Array(data);\n let type = 'array';\n if (!isUtf8(buf)) {\n try {\n data = cptable.utils.decode(936, buf);\n type = 'string';\n } catch {}\n }\n const wb = read(data, { type });\n wb.SheetNames.forEach((name: string) => {\n const sheet: NzSafeAny = wb.Sheets[name];\n ret[name] = sheet_to_json(sheet, { header: 1 });\n });\n return ret;\n }\n\n /**\n * 导入Excel并输出JSON,支持 `<input type=\"file\">`、URL 形式\n */\n import(fileOrUrl: File | string): Promise<{ [key: string]: NzSafeAny[][] }> {\n return new Promise<{ [key: string]: NzSafeAny[][] }>((resolve, reject) => {\n const r = (data: NzSafeAny) => this.ngZone.run(() => resolve(this.read(data)));\n this.init()\n .then(() => {\n // from url\n if (typeof fileOrUrl === 'string') {\n this.http.request('GET', fileOrUrl, { responseType: 'arraybuffer' }).subscribe(\n (res: ArrayBuffer) => r(new Uint8Array(res)),\n (err: NzSafeAny) => reject(err)\n );\n return;\n }\n // from file\n const reader: FileReader = new FileReader();\n reader.onload = (e: NzSafeAny) => r(e.target.result);\n reader.onerror = (e: NzSafeAny) => reject(e);\n reader.readAsArrayBuffer(fileOrUrl);\n })\n .catch(() => reject(`Unable to load xlsx.js`));\n });\n }\n\n @ZoneOutside()\n async export(options: XlsxExportOptions): Promise<XlsxExportResult> {\n return new Promise<XlsxExportResult>((resolve, reject) => {\n this.init()\n .then(() => {\n options = { format: 'xlsx', ...options };\n const {\n writeFile,\n utils: { book_new, aoa_to_sheet, book_append_sheet }\n } = XLSX;\n const wb: NzSafeAny = book_new();\n if (Array.isArray(options.sheets)) {\n (options.sheets as XlsxExportSheet[]).forEach((value: XlsxExportSheet, index: number) => {\n const ws: NzSafeAny = aoa_to_sheet(value.data);\n book_append_sheet(wb, ws, value.name || `Sheet${index + 1}`);\n });\n } else {\n wb.SheetNames = Object.keys(options.sheets);\n wb.Sheets = options.sheets;\n }\n\n if (options.callback) options.callback(wb);\n\n const filename = options.filename || `export.${options.format}`;\n writeFile(wb, filename, {\n bookType: options.format,\n bookSST: false,\n type: 'array',\n ...options.opts\n });\n\n resolve({ filename, wb });\n })\n .catch(err => reject(err));\n });\n }\n\n /**\n * 数据转符号名\n * - `1` => `A`\n * - `27` => `AA`\n * - `703` => `AAA`\n */\n numberToSchema(val: number): string {\n const startCode = 'A'.charCodeAt(0);\n let res = '';\n\n do {\n --val;\n res = String.fromCharCode(startCode + (val % 26)) + res;\n val = (val / 26) >> 0;\n } while (val > 0);\n\n return res;\n }\n}\n","import { Directive, Input } from '@angular/core';\n\nimport { XlsxService } from './xlsx.service';\nimport { XlsxExportOptions } from './xlsx.types';\n\n@Directive({\n selector: '[xlsx]',\n exportAs: 'xlsx',\n host: {\n '(click)': '_click()'\n }\n})\nexport class XlsxDirective {\n @Input('xlsx') data: XlsxExportOptions;\n\n constructor(private srv: XlsxService) {}\n\n _click(): void {\n this.srv.export(this.data);\n }\n}\n","import { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\n\nimport { XlsxDirective } from './xlsx.directive';\n\nconst COMPONENTS = [XlsxDirective];\n\n@NgModule({\n imports: [CommonModule],\n declarations: COMPONENTS,\n exports: COMPONENTS\n})\nexport class XlsxModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;MAgBa,WAAW;IACtB,YACU,IAAgB,EAChB,IAAiB,EACzB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9 +26,9 @@
26
26
  "jszip": "^3.7.1",
27
27
  "xlsx": "^0.17.1",
28
28
  "ngx-countdown": "^12.0.1",
29
- "@delon/theme": "^12.2.3",
30
- "@delon/util": "^12.2.3",
31
- "@delon/acl": "^12.2.3",
29
+ "@delon/theme": "^12.3.0",
30
+ "@delon/util": "^12.3.0",
31
+ "@delon/acl": "^12.3.0",
32
32
  "tslib": "^2.2.0"
33
33
  },
34
34
  "main": "bundles/abc.umd.js",
@@ -1 +1 @@
1
- {"__symbolic":"module","version":4,"metadata":{"XlsxExportOptions":{"__symbolic":"interface"},"XlsxExportSheet":{"__symbolic":"interface"},"XlsxExportResult":{"__symbolic":"interface"},"XlsxService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":16,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":19,"character":18},{"__symbolic":"reference","module":"@delon/util/other","name":"LazyService","line":20,"character":18},{"__symbolic":"reference","module":"@delon/util/config","name":"AlainConfigService","line":21,"character":15},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":22,"character":20}]}],"init":[{"__symbolic":"method"}],"read":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@delon/util/decorator","name":"ZoneOutside","line":37,"character":3}}]}],"import":[{"__symbolic":"method"}],"export":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@delon/util/decorator","name":"ZoneOutside","line":89,"character":3}}]}],"numberToSchema":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"XlsxDirective":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Directive","line":5,"character":1},"arguments":[{"selector":"[xlsx]","exportAs":"xlsx","host":{"(click)":"_click()","$quoted$":["(click)"]}}]}],"members":{"data":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":13,"character":3},"arguments":["xlsx"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"XlsxService"}]}],"_click":[{"__symbolic":"method"}]}},"XlsxModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":7,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":8,"character":12}],"declarations":[{"__symbolic":"reference","name":"XlsxDirective"}],"exports":[{"__symbolic":"reference","name":"XlsxDirective"}]}]}],"members":{}}},"origins":{"XlsxExportOptions":"./xlsx.types","XlsxExportSheet":"./xlsx.types","XlsxExportResult":"./xlsx.types","XlsxService":"./xlsx.service","XlsxDirective":"./xlsx.directive","XlsxModule":"./xlsx.module"},"importAs":"@delon/abc/xlsx"}
1
+ {"__symbolic":"module","version":4,"metadata":{"XlsxExportOptions":{"__symbolic":"interface"},"XlsxExportSheet":{"__symbolic":"interface"},"XlsxExportResult":{"__symbolic":"interface"},"XlsxService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":15,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/common/http","name":"HttpClient","line":18,"character":18},{"__symbolic":"reference","module":"@delon/util/other","name":"LazyService","line":19,"character":18},{"__symbolic":"reference","module":"@delon/util/config","name":"AlainConfigService","line":20,"character":15},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":21,"character":20}]}],"init":[{"__symbolic":"method"}],"read":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@delon/util/decorator","name":"ZoneOutside","line":36,"character":3}}]}],"import":[{"__symbolic":"method"}],"export":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@delon/util/decorator","name":"ZoneOutside","line":85,"character":3}}]}],"numberToSchema":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}},"XlsxDirective":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Directive","line":5,"character":1},"arguments":[{"selector":"[xlsx]","exportAs":"xlsx","host":{"(click)":"_click()","$quoted$":["(click)"]}}]}],"members":{"data":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":13,"character":3},"arguments":["xlsx"]}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"XlsxService"}]}],"_click":[{"__symbolic":"method"}]}},"XlsxModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":7,"character":1},"arguments":[{"imports":[{"__symbolic":"reference","module":"@angular/common","name":"CommonModule","line":8,"character":12}],"declarations":[{"__symbolic":"reference","name":"XlsxDirective"}],"exports":[{"__symbolic":"reference","name":"XlsxDirective"}]}]}],"members":{}}},"origins":{"XlsxExportOptions":"./xlsx.types","XlsxExportSheet":"./xlsx.types","XlsxExportResult":"./xlsx.types","XlsxService":"./xlsx.service","XlsxDirective":"./xlsx.directive","XlsxModule":"./xlsx.module"},"importAs":"@delon/abc/xlsx"}
@@ -8,8 +8,11 @@ export interface XlsxExportOptions {
8
8
  sheets: {
9
9
  [sheet: string]: NzSafeAny;
10
10
  } | XlsxExportSheet[];
11
+ /** File format, default: `xlsx` */
12
+ format?: 'csv' | 'xlsx';
11
13
  /** save file name, default: `export.xlsx` */
12
14
  filename?: string;
15
+ /** See [Writing Options](https://github.com/SheetJS/sheetjs/blob/master/docbits/81_writeopts.md) */
13
16
  opts?: NzSafeAny;
14
17
  /** triggers when saveas */
15
18
  callback?: (wb: NzSafeAny) => void;