@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,43 @@
1
+ const BaseXform = require('../base-xform');
2
+
3
+ class ExtLstXform extends BaseXform {
4
+ get tag() {
5
+ return 'a:extLst';
6
+ }
7
+
8
+ render(xmlStream) {
9
+ xmlStream.openNode(this.tag);
10
+ xmlStream.openNode('a:ext', {
11
+ uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}',
12
+ });
13
+ xmlStream.leafNode('a16:creationId', {
14
+ 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main',
15
+ id: '{00000000-0008-0000-0000-000002000000}',
16
+ });
17
+ xmlStream.closeNode();
18
+ xmlStream.closeNode();
19
+ }
20
+
21
+ parseOpen(node) {
22
+ switch (node.name) {
23
+ case this.tag:
24
+ return true;
25
+ default:
26
+ return true;
27
+ }
28
+ }
29
+
30
+ parseText() {}
31
+
32
+ parseClose(name) {
33
+ switch (name) {
34
+ case this.tag:
35
+ return false;
36
+ default:
37
+ // unprocessed internal nodes
38
+ return true;
39
+ }
40
+ }
41
+ }
42
+
43
+ module.exports = ExtLstXform;
@@ -0,0 +1,44 @@
1
+ const BaseXform = require('../base-xform');
2
+
3
+ /** https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML */
4
+ const EMU_PER_PIXEL_AT_96_DPI = 9525;
5
+
6
+ class ExtXform extends BaseXform {
7
+ constructor(options) {
8
+ super();
9
+
10
+ this.tag = options.tag;
11
+ this.map = {};
12
+ }
13
+
14
+ render(xmlStream, model) {
15
+ xmlStream.openNode(this.tag);
16
+
17
+ const width = Math.floor(model.width * EMU_PER_PIXEL_AT_96_DPI);
18
+ const height = Math.floor(model.height * EMU_PER_PIXEL_AT_96_DPI);
19
+
20
+ xmlStream.addAttribute('cx', width);
21
+ xmlStream.addAttribute('cy', height);
22
+
23
+ xmlStream.closeNode();
24
+ }
25
+
26
+ parseOpen(node) {
27
+ if (node.name === this.tag) {
28
+ this.model = {
29
+ width: parseInt(node.attributes.cx || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
30
+ height: parseInt(node.attributes.cy || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
31
+ };
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+
37
+ parseText(/* text */) {}
38
+
39
+ parseClose(/* name */) {
40
+ return false;
41
+ }
42
+ }
43
+
44
+ module.exports = ExtXform;
@@ -0,0 +1,41 @@
1
+ const BaseXform = require('../base-xform');
2
+
3
+ class HLinkClickXform extends BaseXform {
4
+ get tag() {
5
+ return 'a:hlinkClick';
6
+ }
7
+
8
+ render(xmlStream, model) {
9
+ if (!(model.hyperlinks && model.hyperlinks.rId)) {
10
+ return;
11
+ }
12
+ xmlStream.leafNode(this.tag, {
13
+ 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
14
+ 'r:id': model.hyperlinks.rId,
15
+ tooltip: model.hyperlinks.tooltip,
16
+ });
17
+ }
18
+
19
+ parseOpen(node) {
20
+ switch (node.name) {
21
+ case this.tag:
22
+ this.model = {
23
+ hyperlinks: {
24
+ rId: node.attributes['r:id'],
25
+ tooltip: node.attributes.tooltip,
26
+ },
27
+ };
28
+ return true;
29
+ default:
30
+ return true;
31
+ }
32
+ }
33
+
34
+ parseText() {}
35
+
36
+ parseClose() {
37
+ return false;
38
+ }
39
+ }
40
+
41
+ module.exports = HLinkClickXform;
@@ -0,0 +1,65 @@
1
+ const BaseXform = require('../base-xform');
2
+ const CNvPrXform = require('./c-nv-pr-xform');
3
+ const CNvPicPrXform = require('./c-nv-pic-pr-xform');
4
+
5
+ class NvPicPrXform extends BaseXform {
6
+ constructor() {
7
+ super();
8
+
9
+ this.map = {
10
+ 'xdr:cNvPr': new CNvPrXform(),
11
+ 'xdr:cNvPicPr': new CNvPicPrXform(),
12
+ };
13
+ }
14
+
15
+ get tag() {
16
+ return 'xdr:nvPicPr';
17
+ }
18
+
19
+ render(xmlStream, model) {
20
+ xmlStream.openNode(this.tag);
21
+ this.map['xdr:cNvPr'].render(xmlStream, model);
22
+ this.map['xdr:cNvPicPr'].render(xmlStream, model);
23
+ xmlStream.closeNode();
24
+ }
25
+
26
+ parseOpen(node) {
27
+ if (this.parser) {
28
+ this.parser.parseOpen(node);
29
+ return true;
30
+ }
31
+
32
+ switch (node.name) {
33
+ case this.tag:
34
+ this.reset();
35
+ break;
36
+ default:
37
+ this.parser = this.map[node.name];
38
+ if (this.parser) {
39
+ this.parser.parseOpen(node);
40
+ }
41
+ break;
42
+ }
43
+ return true;
44
+ }
45
+
46
+ parseText() {}
47
+
48
+ parseClose(name) {
49
+ if (this.parser) {
50
+ if (!this.parser.parseClose(name)) {
51
+ this.parser = undefined;
52
+ }
53
+ return true;
54
+ }
55
+ switch (name) {
56
+ case this.tag:
57
+ this.model = this.map['xdr:cNvPr'].model;
58
+ return false;
59
+ default:
60
+ return true;
61
+ }
62
+ }
63
+ }
64
+
65
+ module.exports = NvPicPrXform;
@@ -0,0 +1,63 @@
1
+ const BaseCellAnchorXform = require('./base-cell-anchor-xform');
2
+ const StaticXform = require('../static-xform');
3
+
4
+ const CellPositionXform = require('./cell-position-xform');
5
+ const ExtXform = require('./ext-xform');
6
+ const PicXform = require('./pic-xform');
7
+
8
+ class OneCellAnchorXform extends BaseCellAnchorXform {
9
+ constructor() {
10
+ super();
11
+
12
+ this.map = {
13
+ 'xdr:from': new CellPositionXform({tag: 'xdr:from'}),
14
+ 'xdr:ext': new ExtXform({tag: 'xdr:ext'}),
15
+ 'xdr:pic': new PicXform(),
16
+ 'xdr:clientData': new StaticXform({tag: 'xdr:clientData'}),
17
+ };
18
+ }
19
+
20
+ get tag() {
21
+ return 'xdr:oneCellAnchor';
22
+ }
23
+
24
+ prepare(model, options) {
25
+ this.map['xdr:pic'].prepare(model.picture, options);
26
+ }
27
+
28
+ render(xmlStream, model) {
29
+ xmlStream.openNode(this.tag, {editAs: model.range.editAs || 'oneCell'});
30
+
31
+ this.map['xdr:from'].render(xmlStream, model.range.tl);
32
+ this.map['xdr:ext'].render(xmlStream, model.range.ext);
33
+ this.map['xdr:pic'].render(xmlStream, model.picture);
34
+ this.map['xdr:clientData'].render(xmlStream, {});
35
+
36
+ xmlStream.closeNode();
37
+ }
38
+
39
+ parseClose(name) {
40
+ if (this.parser) {
41
+ if (!this.parser.parseClose(name)) {
42
+ this.parser = undefined;
43
+ }
44
+ return true;
45
+ }
46
+ switch (name) {
47
+ case this.tag:
48
+ this.model.range.tl = this.map['xdr:from'].model;
49
+ this.model.range.ext = this.map['xdr:ext'].model;
50
+ this.model.picture = this.map['xdr:pic'].model;
51
+ return false;
52
+ default:
53
+ // could be some unrecognised tags
54
+ return true;
55
+ }
56
+ }
57
+
58
+ reconcile(model, options) {
59
+ model.medium = this.reconcilePicture(model.picture, options);
60
+ }
61
+ }
62
+
63
+ module.exports = OneCellAnchorXform;
@@ -0,0 +1,77 @@
1
+ const BaseXform = require('../base-xform');
2
+ const StaticXform = require('../static-xform');
3
+
4
+ const BlipFillXform = require('./blip-fill-xform');
5
+ const NvPicPrXform = require('./nv-pic-pr-xform');
6
+
7
+ const spPrJSON = require('./sp-pr');
8
+
9
+ class PicXform extends BaseXform {
10
+ constructor() {
11
+ super();
12
+
13
+ this.map = {
14
+ 'xdr:nvPicPr': new NvPicPrXform(),
15
+ 'xdr:blipFill': new BlipFillXform(),
16
+ 'xdr:spPr': new StaticXform(spPrJSON),
17
+ };
18
+ }
19
+
20
+ get tag() {
21
+ return 'xdr:pic';
22
+ }
23
+
24
+ prepare(model, options) {
25
+ model.index = options.index + 1;
26
+ }
27
+
28
+ render(xmlStream, model) {
29
+ xmlStream.openNode(this.tag);
30
+
31
+ this.map['xdr:nvPicPr'].render(xmlStream, model);
32
+ this.map['xdr:blipFill'].render(xmlStream, model);
33
+ this.map['xdr:spPr'].render(xmlStream, model);
34
+
35
+ xmlStream.closeNode();
36
+ }
37
+
38
+ parseOpen(node) {
39
+ if (this.parser) {
40
+ this.parser.parseOpen(node);
41
+ return true;
42
+ }
43
+ switch (node.name) {
44
+ case this.tag:
45
+ this.reset();
46
+ break;
47
+ default:
48
+ this.parser = this.map[node.name];
49
+ if (this.parser) {
50
+ this.parser.parseOpen(node);
51
+ }
52
+ break;
53
+ }
54
+ return true;
55
+ }
56
+
57
+ parseText() {}
58
+
59
+ parseClose(name) {
60
+ if (this.parser) {
61
+ if (!this.parser.parseClose(name)) {
62
+ this.mergeModel(this.parser.model);
63
+ this.parser = undefined;
64
+ }
65
+ return true;
66
+ }
67
+ switch (name) {
68
+ case this.tag:
69
+ return false;
70
+ default:
71
+ // not quite sure how we get here!
72
+ return true;
73
+ }
74
+ }
75
+ }
76
+
77
+ module.exports = PicXform;
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ tag: 'xdr:spPr',
3
+ c: [
4
+ {
5
+ tag: 'a:xfrm',
6
+ c: [
7
+ {tag: 'a:off', $: {x: '0', y: '0'}},
8
+ {tag: 'a:ext', $: {cx: '0', cy: '0'}},
9
+ ],
10
+ },
11
+ {
12
+ tag: 'a:prstGeom',
13
+ $: {prst: 'rect'},
14
+ c: [{tag: 'a:avLst'}],
15
+ },
16
+ ],
17
+ };
@@ -0,0 +1,62 @@
1
+ const BaseCellAnchorXform = require('./base-cell-anchor-xform');
2
+ const StaticXform = require('../static-xform');
3
+
4
+ const CellPositionXform = require('./cell-position-xform');
5
+ const PicXform = require('./pic-xform');
6
+
7
+ class TwoCellAnchorXform extends BaseCellAnchorXform {
8
+ constructor() {
9
+ super();
10
+
11
+ this.map = {
12
+ 'xdr:from': new CellPositionXform({tag: 'xdr:from'}),
13
+ 'xdr:to': new CellPositionXform({tag: 'xdr:to'}),
14
+ 'xdr:pic': new PicXform(),
15
+ 'xdr:clientData': new StaticXform({tag: 'xdr:clientData'}),
16
+ };
17
+ }
18
+
19
+ get tag() {
20
+ return 'xdr:twoCellAnchor';
21
+ }
22
+
23
+ prepare(model, options) {
24
+ this.map['xdr:pic'].prepare(model.picture, options);
25
+ }
26
+
27
+ render(xmlStream, model) {
28
+ xmlStream.openNode(this.tag, {editAs: model.range.editAs || 'oneCell'});
29
+
30
+ this.map['xdr:from'].render(xmlStream, model.range.tl);
31
+ this.map['xdr:to'].render(xmlStream, model.range.br);
32
+ this.map['xdr:pic'].render(xmlStream, model.picture);
33
+ this.map['xdr:clientData'].render(xmlStream, {});
34
+
35
+ xmlStream.closeNode();
36
+ }
37
+
38
+ parseClose(name) {
39
+ if (this.parser) {
40
+ if (!this.parser.parseClose(name)) {
41
+ this.parser = undefined;
42
+ }
43
+ return true;
44
+ }
45
+ switch (name) {
46
+ case this.tag:
47
+ this.model.range.tl = this.map['xdr:from'].model;
48
+ this.model.range.br = this.map['xdr:to'].model;
49
+ this.model.picture = this.map['xdr:pic'].model;
50
+ return false;
51
+ default:
52
+ // could be some unrecognised tags
53
+ return true;
54
+ }
55
+ }
56
+
57
+ reconcile(model, options) {
58
+ model.medium = this.reconcilePicture(model.picture, options);
59
+ }
60
+ }
61
+
62
+ module.exports = TwoCellAnchorXform;
@@ -0,0 +1,95 @@
1
+ const BaseXform = require('./base-xform');
2
+
3
+ class ListXform extends BaseXform {
4
+ constructor(options) {
5
+ super();
6
+
7
+ this.tag = options.tag;
8
+ this.always = !!options.always;
9
+ this.count = options.count;
10
+ this.empty = options.empty;
11
+ this.$count = options.$count || 'count';
12
+ this.$ = options.$;
13
+ this.childXform = options.childXform;
14
+ this.maxItems = options.maxItems;
15
+ }
16
+
17
+ prepare(model, options) {
18
+ const {childXform} = this;
19
+ if (model) {
20
+ model.forEach((childModel, index) => {
21
+ options.index = index;
22
+ childXform.prepare(childModel, options);
23
+ });
24
+ }
25
+ }
26
+
27
+ render(xmlStream, model) {
28
+ if (this.always || (model && model.length)) {
29
+ xmlStream.openNode(this.tag, this.$);
30
+ if (this.count) {
31
+ xmlStream.addAttribute(this.$count, (model && model.length) || 0);
32
+ }
33
+
34
+ const {childXform} = this;
35
+ (model || []).forEach((childModel, index) => {
36
+ childXform.render(xmlStream, childModel, index);
37
+ });
38
+
39
+ xmlStream.closeNode();
40
+ } else if (this.empty) {
41
+ xmlStream.leafNode(this.tag);
42
+ }
43
+ }
44
+
45
+ parseOpen(node) {
46
+ if (this.parser) {
47
+ this.parser.parseOpen(node);
48
+ return true;
49
+ }
50
+ switch (node.name) {
51
+ case this.tag:
52
+ this.model = [];
53
+ return true;
54
+ default:
55
+ if (this.childXform.parseOpen(node)) {
56
+ this.parser = this.childXform;
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+ }
62
+
63
+ parseText(text) {
64
+ if (this.parser) {
65
+ this.parser.parseText(text);
66
+ }
67
+ }
68
+
69
+ parseClose(name) {
70
+ if (this.parser) {
71
+ if (!this.parser.parseClose(name)) {
72
+ this.model.push(this.parser.model);
73
+ this.parser = undefined;
74
+
75
+ if (this.maxItems && this.model.length > this.maxItems) {
76
+ throw new Error(`Max ${this.childXform.tag} count (${this.maxItems}) exceeded`);
77
+ }
78
+ }
79
+ return true;
80
+ }
81
+
82
+ return false;
83
+ }
84
+
85
+ reconcile(model, options) {
86
+ if (model) {
87
+ const {childXform} = this;
88
+ model.forEach(childModel => {
89
+ childXform.reconcile(childModel, options);
90
+ });
91
+ }
92
+ }
93
+ }
94
+
95
+ module.exports = ListXform;
@@ -0,0 +1,43 @@
1
+ class CacheField {
2
+ constructor({name, sharedItems}) {
3
+ // string type
4
+ //
5
+ // {
6
+ // 'name': 'A',
7
+ // 'sharedItems': ['a1', 'a2', 'a3']
8
+ // }
9
+ //
10
+ // or
11
+ //
12
+ // integer type
13
+ //
14
+ // {
15
+ // 'name': 'D',
16
+ // 'sharedItems': null
17
+ // }
18
+ this.name = name;
19
+ this.sharedItems = sharedItems;
20
+ }
21
+
22
+ render() {
23
+ // PivotCache Field: http://www.datypic.com/sc/ooxml/e-ssml_cacheField-1.html
24
+ // Shared Items: http://www.datypic.com/sc/ooxml/e-ssml_sharedItems-1.html
25
+
26
+ // integer types
27
+ if (this.sharedItems === null) {
28
+ // TK(2023-07-18): left out attributes... minValue="5" maxValue="45"
29
+ return `<cacheField name="${this.name}" numFmtId="0">
30
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" />
31
+ </cacheField>`;
32
+ }
33
+
34
+ // string types
35
+ return `<cacheField name="${this.name}" numFmtId="0">
36
+ <sharedItems count="${this.sharedItems.length}">
37
+ ${this.sharedItems.map(item => `<s v="${item}" />`).join('')}
38
+ </sharedItems>
39
+ </cacheField>`;
40
+ }
41
+ }
42
+
43
+ module.exports = CacheField;
@@ -0,0 +1,77 @@
1
+ const BaseXform = require('../base-xform');
2
+ const CacheField = require('./cache-field');
3
+ const XmlStream = require('../../../utils/xml-stream');
4
+
5
+ class PivotCacheDefinitionXform extends BaseXform {
6
+ constructor() {
7
+ super();
8
+
9
+ this.map = {};
10
+ }
11
+
12
+ prepare(model) {
13
+ // TK
14
+ }
15
+
16
+ get tag() {
17
+ // http://www.datypic.com/sc/ooxml/e-ssml_pivotCacheDefinition.html
18
+ return 'pivotCacheDefinition';
19
+ }
20
+
21
+ render(xmlStream, model) {
22
+ const {sourceSheet, cacheFields} = model;
23
+
24
+ xmlStream.openXml(XmlStream.StdDocAttributes);
25
+ xmlStream.openNode(this.tag, {
26
+ ...PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES,
27
+ 'r:id': 'rId1',
28
+ refreshOnLoad: '1', // important for our implementation to work
29
+ refreshedBy: 'Author',
30
+ refreshedDate: '45125.026046874998',
31
+ createdVersion: '8',
32
+ refreshedVersion: '8',
33
+ minRefreshableVersion: '3',
34
+ recordCount: cacheFields.length + 1,
35
+ });
36
+
37
+ xmlStream.openNode('cacheSource', {type: 'worksheet'});
38
+ xmlStream.leafNode('worksheetSource', {
39
+ ref: sourceSheet.dimensions.shortRange,
40
+ sheet: sourceSheet.name,
41
+ });
42
+ xmlStream.closeNode();
43
+
44
+ xmlStream.openNode('cacheFields', {count: cacheFields.length});
45
+ // Note: keeping this pretty-printed for now to ease debugging.
46
+ xmlStream.writeXml(cacheFields.map(cacheField => new CacheField(cacheField).render()).join('\n '));
47
+ xmlStream.closeNode();
48
+
49
+ xmlStream.closeNode();
50
+ }
51
+
52
+ parseOpen(node) {
53
+ // TK
54
+ }
55
+
56
+ parseText(text) {
57
+ // TK
58
+ }
59
+
60
+ parseClose(name) {
61
+ // TK
62
+ }
63
+
64
+ reconcile(model, options) {
65
+ // TK
66
+ }
67
+ }
68
+
69
+ PivotCacheDefinitionXform.PIVOT_CACHE_DEFINITION_ATTRIBUTES = {
70
+ xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
71
+ 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
72
+ 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
73
+ 'mc:Ignorable': 'xr',
74
+ 'xmlns:xr': 'http://schemas.microsoft.com/office/spreadsheetml/2014/revision',
75
+ };
76
+
77
+ module.exports = PivotCacheDefinitionXform;