@yuanliwei/exceljs 4.4.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 (185) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3024 -0
  3. package/README_zh.md +2878 -0
  4. package/excel.js +13 -0
  5. package/index.d.ts +2040 -0
  6. package/index.ts +2 -0
  7. package/lib/csv/csv.js +191 -0
  8. package/lib/csv/line-buffer.js +74 -0
  9. package/lib/csv/stream-converter.js +135 -0
  10. package/lib/doc/anchor.js +91 -0
  11. package/lib/doc/cell.js +1124 -0
  12. package/lib/doc/column.js +320 -0
  13. package/lib/doc/data/theme1.json +234 -0
  14. package/lib/doc/data-validations.js +19 -0
  15. package/lib/doc/defined-names.js +196 -0
  16. package/lib/doc/enums.js +48 -0
  17. package/lib/doc/image.js +59 -0
  18. package/lib/doc/modelcontainer.js +18 -0
  19. package/lib/doc/note.js +65 -0
  20. package/lib/doc/pivot-table.js +132 -0
  21. package/lib/doc/range.js +257 -0
  22. package/lib/doc/row.js +415 -0
  23. package/lib/doc/table.js +465 -0
  24. package/lib/doc/workbook.js +224 -0
  25. package/lib/doc/worksheet.js +949 -0
  26. package/lib/exceljs.bare.js +13 -0
  27. package/lib/exceljs.browser.js +36 -0
  28. package/lib/exceljs.nodejs.js +14 -0
  29. package/lib/stream/xlsx/hyperlink-reader.js +83 -0
  30. package/lib/stream/xlsx/sheet-comments-writer.js +121 -0
  31. package/lib/stream/xlsx/sheet-rels-writer.js +119 -0
  32. package/lib/stream/xlsx/workbook-reader.js +337 -0
  33. package/lib/stream/xlsx/workbook-writer.js +347 -0
  34. package/lib/stream/xlsx/worksheet-reader.js +374 -0
  35. package/lib/stream/xlsx/worksheet-writer.js +717 -0
  36. package/lib/utils/auto-drain.js +15 -0
  37. package/lib/utils/browser-buffer-decode.js +14 -0
  38. package/lib/utils/browser-buffer-encode.js +15 -0
  39. package/lib/utils/cell-matrix.js +165 -0
  40. package/lib/utils/col-cache.js +287 -0
  41. package/lib/utils/copy-style.js +43 -0
  42. package/lib/utils/encryptor.js +55 -0
  43. package/lib/utils/iterate-stream.js +48 -0
  44. package/lib/utils/parse-sax.js +30 -0
  45. package/lib/utils/shared-formula.js +44 -0
  46. package/lib/utils/shared-strings.js +35 -0
  47. package/lib/utils/stream-base64.js +72 -0
  48. package/lib/utils/stream-buf.js +364 -0
  49. package/lib/utils/string-buf.js +82 -0
  50. package/lib/utils/string-builder.js +35 -0
  51. package/lib/utils/stuttered-pipe.js +67 -0
  52. package/lib/utils/typed-stack.js +24 -0
  53. package/lib/utils/under-dash.js +184 -0
  54. package/lib/utils/utils.js +205 -0
  55. package/lib/utils/xml-stream.js +169 -0
  56. package/lib/utils/zip-stream.js +87 -0
  57. package/lib/xlsx/.rels +11 -0
  58. package/lib/xlsx/calcChain.xml +6 -0
  59. package/lib/xlsx/core.xml +7 -0
  60. package/lib/xlsx/defaultnumformats.js +153 -0
  61. package/lib/xlsx/rel-type.js +20 -0
  62. package/lib/xlsx/styles.xml +41 -0
  63. package/lib/xlsx/workbook.xml +16 -0
  64. package/lib/xlsx/xform/base-xform.js +145 -0
  65. package/lib/xlsx/xform/book/defined-name-xform.js +91 -0
  66. package/lib/xlsx/xform/book/sheet-xform.js +34 -0
  67. package/lib/xlsx/xform/book/workbook-calc-properties-xform.js +26 -0
  68. package/lib/xlsx/xform/book/workbook-pivot-cache-xform.js +29 -0
  69. package/lib/xlsx/xform/book/workbook-properties-xform.js +29 -0
  70. package/lib/xlsx/xform/book/workbook-view-xform.js +53 -0
  71. package/lib/xlsx/xform/book/workbook-xform.js +259 -0
  72. package/lib/xlsx/xform/comment/comment-xform.js +105 -0
  73. package/lib/xlsx/xform/comment/comments-xform.js +82 -0
  74. package/lib/xlsx/xform/comment/style/vml-position-xform.js +39 -0
  75. package/lib/xlsx/xform/comment/style/vml-protection-xform.js +36 -0
  76. package/lib/xlsx/xform/comment/vml-anchor-xform.js +60 -0
  77. package/lib/xlsx/xform/comment/vml-client-data-xform.js +95 -0
  78. package/lib/xlsx/xform/comment/vml-notes-xform.js +107 -0
  79. package/lib/xlsx/xform/comment/vml-shape-xform.js +95 -0
  80. package/lib/xlsx/xform/comment/vml-textbox-xform.js +64 -0
  81. package/lib/xlsx/xform/composite-xform.js +56 -0
  82. package/lib/xlsx/xform/core/app-heading-pairs-xform.js +32 -0
  83. package/lib/xlsx/xform/core/app-titles-of-parts-xform.js +28 -0
  84. package/lib/xlsx/xform/core/app-xform.js +100 -0
  85. package/lib/xlsx/xform/core/content-types-xform.js +135 -0
  86. package/lib/xlsx/xform/core/core-xform.js +136 -0
  87. package/lib/xlsx/xform/core/relationship-xform.js +25 -0
  88. package/lib/xlsx/xform/core/relationships-xform.js +73 -0
  89. package/lib/xlsx/xform/drawing/base-cell-anchor-xform.js +48 -0
  90. package/lib/xlsx/xform/drawing/blip-fill-xform.js +71 -0
  91. package/lib/xlsx/xform/drawing/blip-xform.js +42 -0
  92. package/lib/xlsx/xform/drawing/c-nv-pic-pr-xform.js +38 -0
  93. package/lib/xlsx/xform/drawing/c-nv-pr-xform.js +68 -0
  94. package/lib/xlsx/xform/drawing/cell-position-xform.js +77 -0
  95. package/lib/xlsx/xform/drawing/drawing-xform.js +109 -0
  96. package/lib/xlsx/xform/drawing/ext-lst-xform.js +43 -0
  97. package/lib/xlsx/xform/drawing/ext-xform.js +44 -0
  98. package/lib/xlsx/xform/drawing/hlink-click-xform.js +41 -0
  99. package/lib/xlsx/xform/drawing/nv-pic-pr-xform.js +65 -0
  100. package/lib/xlsx/xform/drawing/one-cell-anchor-xform.js +63 -0
  101. package/lib/xlsx/xform/drawing/pic-xform.js +77 -0
  102. package/lib/xlsx/xform/drawing/sp-pr.js +17 -0
  103. package/lib/xlsx/xform/drawing/two-cell-anchor-xform.js +62 -0
  104. package/lib/xlsx/xform/list-xform.js +95 -0
  105. package/lib/xlsx/xform/pivot-table/cache-field.js +43 -0
  106. package/lib/xlsx/xform/pivot-table/pivot-cache-definition-xform.js +77 -0
  107. package/lib/xlsx/xform/pivot-table/pivot-cache-records-xform.js +103 -0
  108. package/lib/xlsx/xform/pivot-table/pivot-table-xform.js +189 -0
  109. package/lib/xlsx/xform/sheet/auto-filter-xform.js +38 -0
  110. package/lib/xlsx/xform/sheet/cell-xform.js +498 -0
  111. package/lib/xlsx/xform/sheet/cf/cf-rule-xform.js +301 -0
  112. package/lib/xlsx/xform/sheet/cf/cfvo-xform.js +27 -0
  113. package/lib/xlsx/xform/sheet/cf/color-scale-xform.js +45 -0
  114. package/lib/xlsx/xform/sheet/cf/conditional-formatting-xform.js +48 -0
  115. package/lib/xlsx/xform/sheet/cf/conditional-formattings-xform.js +92 -0
  116. package/lib/xlsx/xform/sheet/cf/databar-xform.js +49 -0
  117. package/lib/xlsx/xform/sheet/cf/ext-lst-ref-xform.js +87 -0
  118. package/lib/xlsx/xform/sheet/cf/formula-xform.js +25 -0
  119. package/lib/xlsx/xform/sheet/cf/icon-set-xform.js +47 -0
  120. package/lib/xlsx/xform/sheet/cf-ext/cf-icon-ext-xform.js +27 -0
  121. package/lib/xlsx/xform/sheet/cf-ext/cf-rule-ext-xform.js +98 -0
  122. package/lib/xlsx/xform/sheet/cf-ext/cfvo-ext-xform.js +43 -0
  123. package/lib/xlsx/xform/sheet/cf-ext/conditional-formatting-ext-xform.js +62 -0
  124. package/lib/xlsx/xform/sheet/cf-ext/conditional-formattings-ext-xform.js +50 -0
  125. package/lib/xlsx/xform/sheet/cf-ext/databar-ext-xform.js +98 -0
  126. package/lib/xlsx/xform/sheet/cf-ext/f-ext-xform.js +25 -0
  127. package/lib/xlsx/xform/sheet/cf-ext/icon-set-ext-xform.js +73 -0
  128. package/lib/xlsx/xform/sheet/cf-ext/sqref-ext-xform.js +25 -0
  129. package/lib/xlsx/xform/sheet/col-xform.js +86 -0
  130. package/lib/xlsx/xform/sheet/data-validations-xform.js +257 -0
  131. package/lib/xlsx/xform/sheet/dimension-xform.js +29 -0
  132. package/lib/xlsx/xform/sheet/drawing-xform.js +33 -0
  133. package/lib/xlsx/xform/sheet/ext-lst-xform.js +86 -0
  134. package/lib/xlsx/xform/sheet/header-footer-xform.js +146 -0
  135. package/lib/xlsx/xform/sheet/hyperlink-xform.js +54 -0
  136. package/lib/xlsx/xform/sheet/merge-cell-xform.js +27 -0
  137. package/lib/xlsx/xform/sheet/merges.js +56 -0
  138. package/lib/xlsx/xform/sheet/outline-properties-xform.js +43 -0
  139. package/lib/xlsx/xform/sheet/page-breaks-xform.js +27 -0
  140. package/lib/xlsx/xform/sheet/page-margins-xform.js +49 -0
  141. package/lib/xlsx/xform/sheet/page-setup-properties-xform.js +35 -0
  142. package/lib/xlsx/xform/sheet/page-setup-xform.js +103 -0
  143. package/lib/xlsx/xform/sheet/picture-xform.js +33 -0
  144. package/lib/xlsx/xform/sheet/print-options-xform.js +49 -0
  145. package/lib/xlsx/xform/sheet/row-breaks-xform.js +39 -0
  146. package/lib/xlsx/xform/sheet/row-xform.js +142 -0
  147. package/lib/xlsx/xform/sheet/sheet-format-properties-xform.js +55 -0
  148. package/lib/xlsx/xform/sheet/sheet-properties-xform.js +90 -0
  149. package/lib/xlsx/xform/sheet/sheet-protection-xform.js +89 -0
  150. package/lib/xlsx/xform/sheet/sheet-view-xform.js +202 -0
  151. package/lib/xlsx/xform/sheet/table-part-xform.js +33 -0
  152. package/lib/xlsx/xform/sheet/worksheet-xform.js +548 -0
  153. package/lib/xlsx/xform/simple/boolean-xform.js +31 -0
  154. package/lib/xlsx/xform/simple/date-xform.js +66 -0
  155. package/lib/xlsx/xform/simple/float-xform.js +51 -0
  156. package/lib/xlsx/xform/simple/integer-xform.js +57 -0
  157. package/lib/xlsx/xform/simple/string-xform.js +51 -0
  158. package/lib/xlsx/xform/static-xform.js +64 -0
  159. package/lib/xlsx/xform/strings/phonetic-text-xform.js +98 -0
  160. package/lib/xlsx/xform/strings/rich-text-xform.js +101 -0
  161. package/lib/xlsx/xform/strings/shared-string-xform.js +102 -0
  162. package/lib/xlsx/xform/strings/shared-strings-xform.js +127 -0
  163. package/lib/xlsx/xform/strings/text-xform.js +44 -0
  164. package/lib/xlsx/xform/style/alignment-xform.js +172 -0
  165. package/lib/xlsx/xform/style/border-xform.js +207 -0
  166. package/lib/xlsx/xform/style/color-xform.js +63 -0
  167. package/lib/xlsx/xform/style/dxf-xform.js +111 -0
  168. package/lib/xlsx/xform/style/fill-xform.js +364 -0
  169. package/lib/xlsx/xform/style/font-xform.js +102 -0
  170. package/lib/xlsx/xform/style/numfmt-xform.js +63 -0
  171. package/lib/xlsx/xform/style/protection-xform.js +60 -0
  172. package/lib/xlsx/xform/style/style-xform.js +125 -0
  173. package/lib/xlsx/xform/style/styles-xform.js +527 -0
  174. package/lib/xlsx/xform/style/underline-xform.js +47 -0
  175. package/lib/xlsx/xform/table/auto-filter-xform.js +81 -0
  176. package/lib/xlsx/xform/table/custom-filter-xform.js +33 -0
  177. package/lib/xlsx/xform/table/filter-column-xform.js +96 -0
  178. package/lib/xlsx/xform/table/filter-xform.js +31 -0
  179. package/lib/xlsx/xform/table/table-column-xform.js +44 -0
  180. package/lib/xlsx/xform/table/table-style-info-xform.js +41 -0
  181. package/lib/xlsx/xform/table/table-xform.js +131 -0
  182. package/lib/xlsx/xlsx.js +774 -0
  183. package/lib/xlsx/xml/theme1.js +3 -0
  184. package/lib/xlsx/xml/theme1.xml +318 -0
  185. package/package.json +149 -0
@@ -0,0 +1,24 @@
1
+ class TypedStack {
2
+ constructor(type) {
3
+ this._type = type;
4
+ this._stack = [];
5
+ }
6
+
7
+ get size() {
8
+ return this._stack.length;
9
+ }
10
+
11
+ pop() {
12
+ const tos = this._stack.pop();
13
+ return tos || new this._type();
14
+ }
15
+
16
+ push(instance) {
17
+ if (!(instance instanceof this._type)) {
18
+ throw new Error('Invalid type pushed to TypedStack');
19
+ }
20
+ this._stack.push(instance);
21
+ }
22
+ }
23
+
24
+ module.exports = TypedStack;
@@ -0,0 +1,184 @@
1
+ const {toString} = Object.prototype;
2
+ const escapeHtmlRegex = /["&<>]/;
3
+ const _ = {
4
+ each: function each(obj, cb) {
5
+ if (obj) {
6
+ if (Array.isArray(obj)) {
7
+ obj.forEach(cb);
8
+ } else {
9
+ Object.keys(obj).forEach(key => {
10
+ cb(obj[key], key);
11
+ });
12
+ }
13
+ }
14
+ },
15
+
16
+ some: function some(obj, cb) {
17
+ if (obj) {
18
+ if (Array.isArray(obj)) {
19
+ return obj.some(cb);
20
+ }
21
+ return Object.keys(obj).some(key => cb(obj[key], key));
22
+ }
23
+ return false;
24
+ },
25
+
26
+ every: function every(obj, cb) {
27
+ if (obj) {
28
+ if (Array.isArray(obj)) {
29
+ return obj.every(cb);
30
+ }
31
+ return Object.keys(obj).every(key => cb(obj[key], key));
32
+ }
33
+ return true;
34
+ },
35
+
36
+ map: function map(obj, cb) {
37
+ if (obj) {
38
+ if (Array.isArray(obj)) {
39
+ return obj.map(cb);
40
+ }
41
+ return Object.keys(obj).map(key => cb(obj[key], key));
42
+ }
43
+ return [];
44
+ },
45
+
46
+ keyBy(a, p) {
47
+ return a.reduce((o, v) => {
48
+ o[v[p]] = v;
49
+ return o;
50
+ }, {});
51
+ },
52
+
53
+ isEqual: function isEqual(a, b) {
54
+ const aType = typeof a;
55
+ const bType = typeof b;
56
+ const aArray = Array.isArray(a);
57
+ const bArray = Array.isArray(b);
58
+ let keys;
59
+
60
+ if (aType !== bType) {
61
+ return false;
62
+ }
63
+ switch (typeof a) {
64
+ case 'object':
65
+ if (aArray || bArray) {
66
+ if (aArray && bArray) {
67
+ return (
68
+ a.length === b.length &&
69
+ a.every((aValue, index) => {
70
+ const bValue = b[index];
71
+ return _.isEqual(aValue, bValue);
72
+ })
73
+ );
74
+ }
75
+ return false;
76
+ }
77
+
78
+ if (a === null || b === null) {
79
+ return a === b;
80
+ }
81
+
82
+ // Compare object keys and values
83
+ keys = Object.keys(a);
84
+
85
+ if (Object.keys(b).length !== keys.length) {
86
+ return false;
87
+ }
88
+
89
+ for (const key of keys) {
90
+ if (!b.hasOwnProperty(key)) {
91
+ return false;
92
+ }
93
+ }
94
+
95
+ return _.every(a, (aValue, key) => {
96
+ const bValue = b[key];
97
+ return _.isEqual(aValue, bValue);
98
+ });
99
+
100
+ default:
101
+ return a === b;
102
+ }
103
+ },
104
+
105
+ escapeHtml(html) {
106
+ const regexResult = escapeHtmlRegex.exec(html);
107
+ if (!regexResult) return html;
108
+
109
+ let result = '';
110
+ let escape = '';
111
+ let lastIndex = 0;
112
+ let i = regexResult.index;
113
+ for (; i < html.length; i++) {
114
+ switch (html.charAt(i)) {
115
+ case '"':
116
+ escape = '&quot;';
117
+ break;
118
+ case '&':
119
+ escape = '&amp;';
120
+ break;
121
+ case '\'':
122
+ escape = '&apos;';
123
+ break;
124
+ case '<':
125
+ escape = '&lt;';
126
+ break;
127
+ case '>':
128
+ escape = '&gt;';
129
+ break;
130
+ default:
131
+ continue;
132
+ }
133
+ if (lastIndex !== i) result += html.substring(lastIndex, i);
134
+ lastIndex = i + 1;
135
+ result += escape;
136
+ }
137
+ if (lastIndex !== i) return result + html.substring(lastIndex, i);
138
+ return result;
139
+ },
140
+
141
+ strcmp(a, b) {
142
+ if (a < b) return -1;
143
+ if (a > b) return 1;
144
+ return 0;
145
+ },
146
+
147
+ isUndefined(val) {
148
+ return toString.call(val) === '[object Undefined]';
149
+ },
150
+
151
+ isObject(val) {
152
+ return toString.call(val) === '[object Object]';
153
+ },
154
+
155
+ deepMerge() {
156
+ const target = arguments[0] || {};
157
+ const {length} = arguments;
158
+ // eslint-disable-next-line one-var
159
+ let src, clone, copyIsArray;
160
+
161
+ function assignValue(val, key) {
162
+ src = target[key];
163
+ copyIsArray = Array.isArray(val);
164
+ if (_.isObject(val) || copyIsArray) {
165
+ if (copyIsArray) {
166
+ copyIsArray = false;
167
+ clone = src && Array.isArray(src) ? src : [];
168
+ } else {
169
+ clone = src && _.isObject(src) ? src : {};
170
+ }
171
+ target[key] = _.deepMerge(clone, val);
172
+ } else if (!_.isUndefined(val)) {
173
+ target[key] = val;
174
+ }
175
+ }
176
+
177
+ for (let i = 0; i < length; i++) {
178
+ _.each(arguments[i], assignValue);
179
+ }
180
+ return target;
181
+ },
182
+ };
183
+
184
+ module.exports = _;
@@ -0,0 +1,205 @@
1
+ const fs = require('fs');
2
+
3
+ // useful stuff
4
+ const inherits = function(cls, superCtor, statics, prototype) {
5
+ // eslint-disable-next-line no-underscore-dangle
6
+ cls.super_ = superCtor;
7
+
8
+ if (!prototype) {
9
+ prototype = statics;
10
+ statics = null;
11
+ }
12
+
13
+ if (statics) {
14
+ Object.keys(statics).forEach(i => {
15
+ Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
16
+ });
17
+ }
18
+
19
+ const properties = {
20
+ constructor: {
21
+ value: cls,
22
+ enumerable: false,
23
+ writable: false,
24
+ configurable: true,
25
+ },
26
+ };
27
+ if (prototype) {
28
+ Object.keys(prototype).forEach(i => {
29
+ properties[i] = Object.getOwnPropertyDescriptor(prototype, i);
30
+ });
31
+ }
32
+
33
+ cls.prototype = Object.create(superCtor.prototype, properties);
34
+ };
35
+
36
+ // eslint-disable-next-line no-control-regex
37
+ const xmlDecodeRegex = /[<>&'"\x7F\x00-\x08\x0B-\x0C\x0E-\x1F]/;
38
+ const utils = {
39
+ nop() {},
40
+ promiseImmediate(value) {
41
+ return new Promise(resolve => {
42
+ if (global.setImmediate) {
43
+ setImmediate(() => {
44
+ resolve(value);
45
+ });
46
+ } else {
47
+ // poorman's setImmediate - must wait at least 1ms
48
+ setTimeout(() => {
49
+ resolve(value);
50
+ }, 1);
51
+ }
52
+ });
53
+ },
54
+ inherits,
55
+ dateToExcel(d, date1904) {
56
+ // eslint-disable-next-line no-mixed-operators
57
+ return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
58
+ },
59
+ excelToDate(v, date1904) {
60
+ // eslint-disable-next-line no-mixed-operators
61
+ const millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
62
+ return new Date(millisecondSinceEpoch);
63
+ },
64
+ parsePath(filepath) {
65
+ const last = filepath.lastIndexOf('/');
66
+ return {
67
+ path: filepath.substring(0, last),
68
+ name: filepath.substring(last + 1),
69
+ };
70
+ },
71
+ getRelsPath(filepath) {
72
+ const path = utils.parsePath(filepath);
73
+ return `${path.path}/_rels/${path.name}.rels`;
74
+ },
75
+ xmlEncode(text) {
76
+ const regexResult = xmlDecodeRegex.exec(text);
77
+ if (!regexResult) return text;
78
+
79
+ let result = '';
80
+ let escape = '';
81
+ let lastIndex = 0;
82
+ let i = regexResult.index;
83
+ for (; i < text.length; i++) {
84
+ const charCode = text.charCodeAt(i);
85
+ switch (charCode) {
86
+ case 34: // "
87
+ escape = '&quot;';
88
+ break;
89
+ case 38: // &
90
+ escape = '&amp;';
91
+ break;
92
+ case 39: // '
93
+ escape = '&apos;';
94
+ break;
95
+ case 60: // <
96
+ escape = '&lt;';
97
+ break;
98
+ case 62: // >
99
+ escape = '&gt;';
100
+ break;
101
+ case 127:
102
+ escape = '';
103
+ break;
104
+ default: {
105
+ if (charCode <= 31 && (charCode <= 8 || (charCode >= 11 && charCode !== 13))) {
106
+ escape = '';
107
+ break;
108
+ }
109
+ continue;
110
+ }
111
+ }
112
+ if (lastIndex !== i) result += text.substring(lastIndex, i);
113
+ lastIndex = i + 1;
114
+ if (escape) result += escape;
115
+ }
116
+ if (lastIndex !== i) return result + text.substring(lastIndex, i);
117
+ return result;
118
+ },
119
+ xmlDecode(text) {
120
+ return text.replace(/&([a-z]*);/g, c => {
121
+ switch (c) {
122
+ case '&lt;':
123
+ return '<';
124
+ case '&gt;':
125
+ return '>';
126
+ case '&amp;':
127
+ return '&';
128
+ case '&apos;':
129
+ return '\'';
130
+ case '&quot;':
131
+ return '"';
132
+ default:
133
+ return c;
134
+ }
135
+ });
136
+ },
137
+ validInt(value) {
138
+ const i = parseInt(value, 10);
139
+ return !Number.isNaN(i) ? i : 0;
140
+ },
141
+
142
+ isDateFmt(fmt) {
143
+ if (!fmt) {
144
+ return false;
145
+ }
146
+
147
+ // must remove all chars inside quotes and []
148
+ fmt = fmt.replace(/\[[^\]]*]/g, '');
149
+ fmt = fmt.replace(/"[^"]*"/g, '');
150
+ // then check for date formatting chars
151
+ const result = fmt.match(/[ymdhMsb]+/) !== null;
152
+ return result;
153
+ },
154
+
155
+ fs: {
156
+ exists(path) {
157
+ return new Promise(resolve => {
158
+ fs.access(path, fs.constants.F_OK, err => {
159
+ resolve(!err);
160
+ });
161
+ });
162
+ },
163
+ },
164
+
165
+ toIsoDateString(dt) {
166
+ return dt.toIsoString().subsstr(0, 10);
167
+ },
168
+
169
+ parseBoolean(value) {
170
+ return value === true || value === 'true' || value === 1 || value === '1';
171
+ },
172
+
173
+ *range(start, stop, step = 1) {
174
+ const compareOrder = step > 0 ? (a, b) => a < b : (a, b) => a > b;
175
+ for (let value = start; compareOrder(value, stop); value += step) {
176
+ yield value;
177
+ }
178
+ },
179
+
180
+ toSortedArray(values) {
181
+ const result = Array.from(values);
182
+
183
+ // Note: per default, `Array.prototype.sort()` converts values
184
+ // to strings when comparing. Here, if we have numbers, we use
185
+ // numeric sort.
186
+ if (result.every(item => Number.isFinite(item))) {
187
+ const compareNumbers = (a, b) => a - b;
188
+ return result.sort(compareNumbers);
189
+ }
190
+
191
+ return result.sort();
192
+ },
193
+
194
+ objectFromProps(props, value = null) {
195
+ // *Note*: Using `reduce` as `Object.fromEntries` requires Node 12+;
196
+ // ExcelJs is >=8.3.0 (as of 2023-10-08).
197
+ // return Object.fromEntries(props.map(property => [property, value]));
198
+ return props.reduce((result, property) => {
199
+ result[property] = value;
200
+ return result;
201
+ }, {});
202
+ },
203
+ };
204
+
205
+ module.exports = utils;
@@ -0,0 +1,169 @@
1
+ const _ = require('./under-dash');
2
+
3
+ const utils = require('./utils');
4
+
5
+ // constants
6
+ const OPEN_ANGLE = '<';
7
+ const CLOSE_ANGLE = '>';
8
+ const OPEN_ANGLE_SLASH = '</';
9
+ const CLOSE_SLASH_ANGLE = '/>';
10
+
11
+ function pushAttribute(xml, name, value) {
12
+ xml.push(` ${name}="${utils.xmlEncode(value.toString())}"`);
13
+ }
14
+ function pushAttributes(xml, attributes) {
15
+ if (attributes) {
16
+ const tmp = [];
17
+ _.each(attributes, (value, name) => {
18
+ if (value !== undefined) {
19
+ pushAttribute(tmp, name, value);
20
+ }
21
+ });
22
+ xml.push(tmp.join(""));
23
+ }
24
+ }
25
+
26
+ class XmlStream {
27
+ constructor() {
28
+ this._xml = [];
29
+ this._stack = [];
30
+ this._rollbacks = [];
31
+ }
32
+
33
+ get tos() {
34
+ return this._stack.length ? this._stack[this._stack.length - 1] : undefined;
35
+ }
36
+
37
+ get cursor() {
38
+ // handy way to track whether anything has been added
39
+ return this._xml.length;
40
+ }
41
+
42
+ openXml(docAttributes) {
43
+ const xml = this._xml;
44
+ // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
45
+ xml.push('<?xml');
46
+ pushAttributes(xml, docAttributes);
47
+ xml.push('?>\n');
48
+ }
49
+
50
+ openNode(name, attributes) {
51
+ const parent = this.tos;
52
+ const xml = this._xml;
53
+ if (parent && this.open) {
54
+ xml.push(CLOSE_ANGLE);
55
+ }
56
+
57
+ this._stack.push(name);
58
+
59
+ // start streaming node
60
+ xml.push(OPEN_ANGLE);
61
+ xml.push(name);
62
+ pushAttributes(xml, attributes);
63
+ this.leaf = true;
64
+ this.open = true;
65
+ }
66
+
67
+ addAttribute(name, value) {
68
+ if (!this.open) {
69
+ throw new Error('Cannot write attributes to node if it is not open');
70
+ }
71
+ if (value !== undefined) {
72
+ pushAttribute(this._xml, name, value);
73
+ }
74
+ }
75
+
76
+ addAttributes(attrs) {
77
+ if (!this.open) {
78
+ throw new Error('Cannot write attributes to node if it is not open');
79
+ }
80
+ pushAttributes(this._xml, attrs);
81
+ }
82
+
83
+ writeText(text) {
84
+ const xml = this._xml;
85
+ if (this.open) {
86
+ xml.push(CLOSE_ANGLE);
87
+ this.open = false;
88
+ }
89
+ this.leaf = false;
90
+ xml.push(utils.xmlEncode(text.toString()));
91
+ }
92
+
93
+ writeXml(xml) {
94
+ if (this.open) {
95
+ this._xml.push(CLOSE_ANGLE);
96
+ this.open = false;
97
+ }
98
+ this.leaf = false;
99
+ this._xml.push(xml);
100
+ }
101
+
102
+ closeNode() {
103
+ const node = this._stack.pop();
104
+ const xml = this._xml;
105
+ if (this.leaf) {
106
+ xml.push(CLOSE_SLASH_ANGLE);
107
+ } else {
108
+ xml.push(OPEN_ANGLE_SLASH);
109
+ xml.push(node);
110
+ xml.push(CLOSE_ANGLE);
111
+ }
112
+ this.open = false;
113
+ this.leaf = false;
114
+ }
115
+
116
+ leafNode(name, attributes, text) {
117
+ this.openNode(name, attributes);
118
+ if (text !== undefined) {
119
+ // zeros need to be written
120
+ this.writeText(text);
121
+ }
122
+ this.closeNode();
123
+ }
124
+
125
+ closeAll() {
126
+ while (this._stack.length) {
127
+ this.closeNode();
128
+ }
129
+ }
130
+
131
+ addRollback() {
132
+ this._rollbacks.push({
133
+ xml: this._xml.length,
134
+ stack: this._stack.length,
135
+ leaf: this.leaf,
136
+ open: this.open,
137
+ });
138
+ return this.cursor;
139
+ }
140
+
141
+ commit() {
142
+ this._rollbacks.pop();
143
+ }
144
+
145
+ rollback() {
146
+ const r = this._rollbacks.pop();
147
+ if (this._xml.length > r.xml) {
148
+ this._xml.splice(r.xml, this._xml.length - r.xml);
149
+ }
150
+ if (this._stack.length > r.stack) {
151
+ this._stack.splice(r.stack, this._stack.length - r.stack);
152
+ }
153
+ this.leaf = r.leaf;
154
+ this.open = r.open;
155
+ }
156
+
157
+ get xml() {
158
+ this.closeAll();
159
+ return this._xml.join('');
160
+ }
161
+ }
162
+
163
+ XmlStream.StdDocAttributes = {
164
+ version: '1.0',
165
+ encoding: 'UTF-8',
166
+ standalone: 'yes',
167
+ };
168
+
169
+ module.exports = XmlStream;
@@ -0,0 +1,87 @@
1
+ const events = require('events');
2
+ const JSZip = require('jszip');
3
+
4
+ const StreamBuf = require('./stream-buf');
5
+ const {stringToBuffer} = require('./browser-buffer-encode');
6
+
7
+ // =============================================================================
8
+ // The ZipWriter class
9
+ // Packs streamed data into an output zip stream
10
+ class ZipWriter extends events.EventEmitter {
11
+ constructor(options) {
12
+ super();
13
+ this.options = Object.assign(
14
+ {
15
+ type: 'nodebuffer',
16
+ compression: 'DEFLATE',
17
+ },
18
+ options
19
+ );
20
+
21
+ this.zip = new JSZip();
22
+ this.stream = new StreamBuf();
23
+ }
24
+
25
+ append(data, options) {
26
+ if (options.hasOwnProperty('base64') && options.base64) {
27
+ this.zip.file(options.name, data, {base64: true});
28
+ } else {
29
+ // https://www.npmjs.com/package/process
30
+ if (process.browser && typeof data === 'string') {
31
+ // use TextEncoder in browser
32
+ data = stringToBuffer(data);
33
+ }
34
+ this.zip.file(options.name, data);
35
+ }
36
+ }
37
+
38
+ async finalize() {
39
+ const content = await this.zip.generateAsync(this.options);
40
+ this.stream.end(content);
41
+ this.emit('finish');
42
+ }
43
+
44
+ // ==========================================================================
45
+ // Stream.Readable interface
46
+ read(size) {
47
+ return this.stream.read(size);
48
+ }
49
+
50
+ setEncoding(encoding) {
51
+ return this.stream.setEncoding(encoding);
52
+ }
53
+
54
+ pause() {
55
+ return this.stream.pause();
56
+ }
57
+
58
+ resume() {
59
+ return this.stream.resume();
60
+ }
61
+
62
+ isPaused() {
63
+ return this.stream.isPaused();
64
+ }
65
+
66
+ pipe(destination, options) {
67
+ return this.stream.pipe(destination, options);
68
+ }
69
+
70
+ unpipe(destination) {
71
+ return this.stream.unpipe(destination);
72
+ }
73
+
74
+ unshift(chunk) {
75
+ return this.stream.unshift(chunk);
76
+ }
77
+
78
+ wrap(stream) {
79
+ return this.stream.wrap(stream);
80
+ }
81
+ }
82
+
83
+ // =============================================================================
84
+
85
+ module.exports = {
86
+ ZipWriter,
87
+ };
package/lib/xlsx/.rels ADDED
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3
+ <%relationships.forEach(function(r) {%>
4
+ <Relationship
5
+ Id="<%=r.rId%>"
6
+ Type="<%=r.type%>"
7
+ Target="<%=r.target%>" <% if (r.targetMode) {%>
8
+ TargetMode="<%=r.targetMode%>"<%}%>
9
+ />
10
+ <%});%>
11
+ </Relationships>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <calcChain xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
3
+ <% formulae.forEach(function(formula) { %>
4
+ <c r="<%=formula.address%>" i="<%=formula.i%>" <% if(formula.l) { %>l="<%=formula.l%>"<% } %>/>
5
+ <% }); %>
6
+ </calcChain>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <dc:creator><%=creator%></dc:creator>
4
+ <cp:lastModifiedBy><%=lastModifiedBy%></cp:lastModifiedBy>
5
+ <dcterms:created xsi:type="dcterms:W3CDTF"><%=created.toISOString().replace(/\.\d{3}/,"")%></dcterms:created>
6
+ <dcterms:modified xsi:type="dcterms:W3CDTF"><%=modified.toISOString().replace(/\.\d{3}/,"")%></dcterms:modified>
7
+ </cp:coreProperties>