@dztabel/excel-kit 0.0.0-stage → 0.10.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 (97) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/DISTRIBUTION.md +13 -0
  3. package/LICENSE +45 -0
  4. package/README.md +74 -2
  5. package/SKILL.md +52 -0
  6. package/THIRD-PARTY-NOTICES.txt +3050 -0
  7. package/VALIDATION.md +46 -0
  8. package/bin/excel-kit.cjs +50 -0
  9. package/package.json +19 -4
  10. package/recipes/README.md +31 -0
  11. package/recipes/audit-and-repair/README.md +30 -0
  12. package/recipes/audit-and-repair/inspect.json +7 -0
  13. package/recipes/audit-and-repair/recipe.js +48 -0
  14. package/recipes/audit-and-repair/request.json +22 -0
  15. package/recipes/audit-and-repair/sample/clean-control.xlsx +0 -0
  16. package/recipes/audit-and-repair/sample/expected.json +15 -0
  17. package/recipes/audit-and-repair/sample/model-to-check.xlsx +0 -0
  18. package/recipes/edit-protected-workbook/README.md +30 -0
  19. package/recipes/edit-protected-workbook/prepare.json +10 -0
  20. package/recipes/edit-protected-workbook/recipe.js +41 -0
  21. package/recipes/edit-protected-workbook/request.json +14 -0
  22. package/recipes/fill-template/README.md +30 -0
  23. package/recipes/fill-template/recipe.js +46 -0
  24. package/recipes/fill-template/request.json +18 -0
  25. package/recipes/fill-template/sample/derive-template.request.json +22 -0
  26. package/recipes/fill-template/sample/original/LICENSE +201 -0
  27. package/recipes/fill-template/sample/original/cf-hyperlink-image-protection.xlsx +0 -0
  28. package/recipes/fill-template/sample/template.xlsx +0 -0
  29. package/recipes/import-clean-append/README.md +30 -0
  30. package/recipes/import-clean-append/prepare.json +8 -0
  31. package/recipes/import-clean-append/recipe.js +77 -0
  32. package/recipes/import-clean-append/request.json +22 -0
  33. package/recipes/import-clean-append/sample/incoming-1.csv +4 -0
  34. package/recipes/import-clean-append/sample/incoming-2.csv +3 -0
  35. package/recipes/import-clean-append/sample/trading-table.xlsx +0 -0
  36. package/recipes/inventory-media/README.md +31 -0
  37. package/recipes/inventory-media/prepare.json +9 -0
  38. package/recipes/inventory-media/recipe.js +44 -0
  39. package/recipes/inventory-media/request.json +7 -0
  40. package/recipes/inventory-media/sample/LICENSE +268 -0
  41. package/recipes/inventory-media/sample/NOTICE +36 -0
  42. package/recipes/inventory-media/sample/WithEmbeded.xlsx +0 -0
  43. package/recipes/inventory-media/sample/blue.png +0 -0
  44. package/recipes/inventory-media/sample/green.jpg +0 -0
  45. package/recipes/normalize-codes/README.md +30 -0
  46. package/recipes/normalize-codes/prepare.json +73 -0
  47. package/recipes/normalize-codes/recipe.js +34 -0
  48. package/recipes/normalize-codes/request.json +7 -0
  49. package/recipes/normalize-codes/sample/trading-table.xlsx +0 -0
  50. package/recipes/pivot-by-slicer/README.md +30 -0
  51. package/recipes/pivot-by-slicer/prepare.json +11 -0
  52. package/recipes/pivot-by-slicer/recipe.js +34 -0
  53. package/recipes/pivot-by-slicer/request.json +14 -0
  54. package/recipes/repair-and-test-model/README.md +13 -0
  55. package/recipes/repair-and-test-model/workflow.py +108 -0
  56. package/recipes/roll-forward-period/README.md +30 -0
  57. package/recipes/roll-forward-period/prepare.json +10 -0
  58. package/recipes/roll-forward-period/recipe.js +49 -0
  59. package/recipes/roll-forward-period/request.json +13 -0
  60. package/recipes/roll-forward-period/sample/budget-template.xlsx +0 -0
  61. package/recipes/style-matching-sheets/README.md +28 -0
  62. package/recipes/style-matching-sheets/recipe.js +38 -0
  63. package/recipes/style-matching-sheets/request.json +17 -0
  64. package/recipes/style-matching-sheets/sample/build-workbook.request.json +13 -0
  65. package/recipes/style-matching-sheets/sample/report-tables.xlsx +0 -0
  66. package/recipes/update-assumptions/README.md +29 -0
  67. package/recipes/update-assumptions/recipe.js +66 -0
  68. package/recipes/update-assumptions/request.json +10 -0
  69. package/recipes/update-assumptions/sample/build-model.request.json +12 -0
  70. package/recipes/update-assumptions/sample/cost-model.xlsx +0 -0
  71. package/recipes/update-matching-records/README.md +35 -0
  72. package/recipes/update-matching-records/incomplete-strict.json +33 -0
  73. package/recipes/update-matching-records/incomplete.json +32 -0
  74. package/recipes/update-matching-records/prepare-incomplete.json +21 -0
  75. package/recipes/update-matching-records/recipe.js +35 -0
  76. package/recipes/update-matching-records/request.json +29 -0
  77. package/recipes/update-matching-records/sample/trading-table.xlsx +0 -0
  78. package/reference/api.md +59 -0
  79. package/reference/audit.md +50 -0
  80. package/reference/calculation.md +82 -0
  81. package/reference/cost.md +61 -0
  82. package/reference/deliverable.md +66 -0
  83. package/reference/editing-and-saving.md +69 -0
  84. package/reference/errors.md +65 -0
  85. package/reference/external-links.md +39 -0
  86. package/reference/function-limits.md +30 -0
  87. package/reference/paging.md +63 -0
  88. package/reference/pivots.md +46 -0
  89. package/reference/presentation.md +11 -0
  90. package/reference/protection.md +63 -0
  91. package/reference/reading.md +70 -0
  92. package/reference/scripts.md +74 -0
  93. package/reference/selection.md +43 -0
  94. package/reference/session-loop.md +62 -0
  95. package/reference/sessions.md +54 -0
  96. package/reference/unsupported.md +31 -0
  97. package/release.json +41 -0
@@ -0,0 +1,268 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+
205
+ APACHE POI SUBCOMPONENTS:
206
+
207
+ Apache POI includes subcomponents with separate copyright notices and
208
+ license terms. Your use of these subcomponents is subject to the terms
209
+ and conditions of the following licenses:
210
+
211
+
212
+ Office Open XML schemas (poi-ooxml-full-*.jar)
213
+
214
+ The Office Open XML schema definitions used by Apache POI are
215
+ a part of the Office Open XML ECMA Specification (ECMA-376, [1]).
216
+ As defined in section 9.4 of the ECMA bylaws [2], this specification
217
+ is available to all interested parties without restriction:
218
+
219
+ 9.4 All documents when approved shall be made available to
220
+ all interested parties without restriction.
221
+
222
+ Furthermore, both Microsoft and Adobe have granted patent licenses
223
+ to this work [3,4,5].
224
+
225
+ [1] https://www.ecma-international.org/publications/standards/Ecma-376.htm
226
+ [2] https://www.ecma-international.org/memento/Ecmabylaws.htm
227
+ [3] https://www.microsoft.com/openspecifications/en/us/programs/osp/default.aspx
228
+ [4] https://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
229
+ Patent%20statements%20ok/ECMA-376%20Edition%202%20Microsoft%20Patent%20Declaration.pdf
230
+ [5] https://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
231
+ Patent%20statements%20ok/ECMA-376%20Adobe%20Patent%20Declaration.pdf
232
+
233
+
234
+ org.apache.poi.util.ReplacingInputStream is based on code from
235
+ inbot-utils (https://github.com/Inbot/inbot-utils)
236
+
237
+ The MIT License (MIT)
238
+
239
+ Copyright (c) 2015 Inbot
240
+
241
+ Permission is hereby granted, free of charge, to any person obtaining a copy
242
+ of this software and associated documentation files (the "Software"), to deal
243
+ in the Software without restriction, including without limitation the rights
244
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
245
+ copies of the Software, and to permit persons to whom the Software is
246
+ furnished to do so, subject to the following conditions:
247
+
248
+ The above copyright notice and this permission notice shall be included in all
249
+ copies or substantial portions of the Software.
250
+
251
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
252
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
253
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
254
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
255
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
256
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
257
+ SOFTWARE.
258
+
259
+ ExceptionUtils is derived from `scala.util.control.NonFatal` in scala-library
260
+ which was released under the Apache 2.0 license.
261
+ Copyright (c) 2002-2023 EPFL
262
+ Copyright (c) 2011-2023 Lightbend, Inc.
263
+
264
+ The POI Source Release bundles the Gradle Wrapper. (https://docs.gradle.org/current/userguide/gradle_wrapper.html)
265
+ This is released under the Apache License, v2.0.
266
+ Copyright © 2015-2021 the original authors.
267
+
268
+ The wrapper.gradle file was developed by the Apache Kafka project and is released under the Apache License, v2.0.
@@ -0,0 +1,36 @@
1
+ Apache POI
2
+ Copyright 2003-2026 The Apache Software Foundation
3
+
4
+ This product includes software developed at
5
+ The Apache Software Foundation (https://www.apache.org/).
6
+
7
+ This product contains parts that were originally based on software from BEA.
8
+ Copyright (c) 2000-2003, BEA Systems, <http://www.bea.com/> (dead link),
9
+ which was acquired by Oracle Corporation in 2008.
10
+ <http://www.oracle.com/us/corporate/Acquisitions/bea/index.html>
11
+ <https://en.wikipedia.org/wiki/BEA_Systems>
12
+ Note: The ASF Secretary has on hand a Software Grant Agreement (SGA) from
13
+ BEA Systems, Inc. dated 9 Sep 2003 for XMLBeans signed by their EVP/CFO.
14
+
15
+ This product contains W3C XML Schema documents. Copyright 2001-2003 (c)
16
+ World Wide Web Consortium (Massachusetts Institute of Technology, European
17
+ Research Consortium for Informatics and Mathematics, Keio University)
18
+
19
+ This product contains the chunks_parse_cmds.tbl file from the vsdump program.
20
+ Copyright (C) 2006-2007 Valek Filippov (frob@df.ru)
21
+
22
+ This product contains parts of the eID Applet project
23
+ <http://eid-applet.googlecode.com> and <https://github.com/e-Contract/eid-applet>.
24
+ Copyright (c) 2009-2018
25
+ FedICT (federal ICT department of Belgium), e-Contract.be BVBA (https://www.e-contract.be),
26
+ Bart Hanssens from FedICT
27
+
28
+ ExceptionUtils is derived from `scala.util.control.NonFatal` in scala-library
29
+ which was released under the Apache 2.0 license.
30
+
31
+ Copyright (c) 2002-2023 EPFL
32
+ Copyright (c) 2011-2023 Lightbend, Inc.
33
+
34
+ Scala includes software developed at
35
+ LAMP/EPFL (https://lamp.epfl.ch/) and
36
+ Lightbend, Inc. (https://www.lightbend.com/).
@@ -0,0 +1,30 @@
1
+ # 用正则在整本工作簿里规范化编号
2
+
3
+ 用一个正则表达式在整本工作簿(含隐藏表)里把不规范的编号改成规范形式,再用同一个搜索证明没有残留;有残留就不发布。
4
+
5
+ ## 运行
6
+
7
+ 在本目录下依次执行:
8
+
9
+ 1. `excel-kit run prepare.json`:向样本注入不规范编号,生成 `sample/irregular-codes.xlsx`。
10
+ 2. `excel-kit script request.json`:生成 `normalized-codes.xlsx`。
11
+
12
+ `request.json` 里的路径相对本目录。脚本本体是 `recipe.js`,开头的注释列出了全部参数。
13
+
14
+ ## 参数
15
+
16
+ `pattern` 与 `replacement` 是正则和替换式(支持 `$1`);`caseSensitive` 默认 false;`sheets` 可限定工作表。
17
+
18
+ ## 样本与许可
19
+
20
+ `sample/trading-table.xlsx` 是本仓库第三阶段合成的 Table 样本,可再分发。样本里的编号本来是规范的,不规范的写法(CSV 里 `SKU-0004-X` 那种形态)由 `prepare.json` 注入。
21
+
22
+ ## 样本上的结果
23
+
24
+ 4 个单元格、5 处替换(有一格的句子里嵌了两个编号);大小写不同的写法也命中;`SKU-12-X` 位数不符合模式,按模式不动;公式拼出的结果不是存储文本,不在替换范围。
25
+
26
+ ## 要点
27
+
28
+ - 替换只作用于存储的文本,不改公式结果。
29
+ - 规范后的编号仍是文本,前导零保留。
30
+ - 再跑一次找不到任何匹配,不写文件。
@@ -0,0 +1,73 @@
1
+ {
2
+ "input": "sample/trading-table.xlsx",
3
+ "output": "sample/irregular-codes.xlsx",
4
+ "operations": [
5
+ {
6
+ "op": "table.append",
7
+ "table": "交易明细",
8
+ "columns": [
9
+ "编号",
10
+ "名称",
11
+ "日期",
12
+ "数量",
13
+ "单价"
14
+ ],
15
+ "values": [
16
+ [
17
+ "SKU-0004-X",
18
+ "服务",
19
+ 46081,
20
+ 2,
21
+ 15.5
22
+ ],
23
+ [
24
+ "sku-0005-x",
25
+ "材料",
26
+ 46082,
27
+ 1,
28
+ 7
29
+ ],
30
+ [
31
+ "SKU-12-X",
32
+ "短编号",
33
+ 46083,
34
+ 1,
35
+ 3
36
+ ]
37
+ ]
38
+ },
39
+ {
40
+ "op": "sheet.add",
41
+ "name": "对照"
42
+ },
43
+ {
44
+ "op": "write",
45
+ "sheet": "对照",
46
+ "range": "A1",
47
+ "values": [
48
+ [
49
+ "引用编号",
50
+ "说明"
51
+ ],
52
+ [
53
+ "SKU-0004-X",
54
+ "来自 CSV 的写法"
55
+ ],
56
+ [
57
+ "0002",
58
+ "已经规范"
59
+ ],
60
+ [
61
+ "见 SKU-0001-X 与 SKU-0003-X",
62
+ "嵌在句子里"
63
+ ],
64
+ [
65
+ {
66
+ "formula": "=\"SKU-\"&\"0009\"&\"-X\""
67
+ },
68
+ "公式结果,不是存储文本"
69
+ ]
70
+ ]
71
+ }
72
+ ]
73
+ }
@@ -0,0 +1,34 @@
1
+ // Normalize a code format across the whole workbook with one regular
2
+ // expression, then prove with a search that nothing in the old format is left.
3
+ //
4
+ // args: { pattern, replacement, caseSensitive?, sheets? }
5
+ // pattern ECMAScript regular expression for the irregular form, e.g. "SKU-(\\d{4})-X"
6
+ // replacement replacement with $1-style tokens, e.g. "$1"
7
+ // sheets optional list of sheet names; default is every sheet, hidden ones included
8
+ const must = (response, what) => {
9
+ if (!response.ok) {
10
+ const first = response.calculation?.diagnostics?.[0];
11
+ throw new Error(response.error ? `${what}: ${response.error.code} ${response.error.message}` : `${what}: CALCULATION_INCOMPLETE calculation ${response.calculation?.status}${first ? ` (${first.code} at ${first.sheet}!${first.cell}: ${first.message})` : ''}`);
12
+ }
13
+ return response;
14
+ };
15
+ const caseSensitive = args.caseSensitive ?? false;
16
+ const search = sheet => ({ ...(sheet ? { sheet } : {}), field: 'value', value: { type: 'string', value: args.pattern }, match: 'contains', syntax: 'regex', caseSensitive, limit: 1000 });
17
+ const scopes = args.sheets ?? [undefined];
18
+
19
+ const before = must(await wb.query({ find: scopes.map(search) }), 'Find codes').find;
20
+ const found = before.reduce((sum, result) => sum + result.total, 0);
21
+ if (found === 0) return { found: 0, replacements: 0, remaining: 0, cells: [] };
22
+
23
+ let replacements = 0;
24
+ for (const sheet of scopes) {
25
+ const step = await wb.run({ op: 'range.replace', ...(sheet ? { sheet } : {}), find: args.pattern, replacement: args.replacement, syntax: 'regex', match: 'partial', caseSensitive });
26
+ if (!step.ok) throw new Error(`Replacement failed: ${step.error.code} ${step.error.message}`);
27
+ for (const event of step.result.rangeOperations ?? []) replacements += event.replacements ?? 0;
28
+ }
29
+
30
+ // The same search, against the edited workbook. Anything left is a reason to stop, not to publish.
31
+ const after = must(await wb.query({ find: scopes.map(search) }), 'Find codes').find;
32
+ const remaining = after.reduce((sum, result) => sum + result.total, 0);
33
+ if (remaining > 0) throw new Error(`${remaining} cells still match ${args.pattern}: ${after.flatMap(result => result.items).slice(0, 5).map(item => `${item.sheet}!${item.cell}`).join(', ')}`);
34
+ return { found, replacements, remaining, cells: before.flatMap(result => result.items.map(item => `${item.sheet}!${item.cell}`)) };
@@ -0,0 +1,7 @@
1
+ {
2
+ "input": "sample/irregular-codes.xlsx",
3
+ "output": "normalized-codes.xlsx",
4
+ "scriptPath": "recipe.js",
5
+ "strict": true,
6
+ "arguments": { "pattern": "SKU-(\\d{4})-X", "replacement": "$1", "caseSensitive": false }
7
+ }
@@ -0,0 +1,30 @@
1
+ # 追加明细、刷新透视,按切片器逐项读取下游公式
2
+
3
+ 向明细 Table 追加记录并刷新透视,然后按切片器的每个选项逐一选择,读取依赖透视结果的公式在每种选择下的值,最后清除选择并核对各项之和等于总计。
4
+
5
+ ## 运行
6
+
7
+ 在本目录下依次执行:
8
+
9
+ 1. `excel-kit run prepare.json`:合成明细 Table、透视、切片器和两条下游公式,生成 `sales.xlsx`。
10
+ 2. `excel-kit script request.json`:生成 `sales-updated.xlsx`。
11
+
12
+ `request.json` 里的路径相对本目录。脚本本体是 `recipe.js`,开头的注释列出了全部参数。
13
+
14
+ ## 参数
15
+
16
+ `append` 是要追加的记录;`pivot`、`slicer` 指向对象;`items` 是要逐项选择的切片器选项;`read` 是下游单元格;`total` 指明哪个读取项可以跨选项相加,用于一致性核对。
17
+
18
+ ## 样本与许可
19
+
20
+ 样本完全由 `prepare.json` 用公开操作合成,没有外部来源。
21
+
22
+ ## 样本上的结果
23
+
24
+ 追加两条记录后,华东 150(泵 100)、华北 95(泵 70)、华南 70(泵 40),不筛选时总计 315(泵 210)。
25
+
26
+ ## 要点
27
+
28
+ - 依赖透视结果的公式只在刷新该透视的那一步里计算:更早步骤留下的透视结果不会被当作当前值,之后的只读计算会得到 `PIVOT_RESULT_UNAVAILABLE`。所以每次选择都用该步自带的 `read` 读取。
29
+ - `items` 漏掉一个选项时,各项之和对不上总计,配方拒绝发布。
30
+ - 下游公式直接用整列引用读透视结果(`INDEX(透视!B:B, MATCH("总计", 透视!A:A, 0))`),透视行数变化时不必改范围。
@@ -0,0 +1,11 @@
1
+ {
2
+ "create": { "sheets": ["明细", "透视", "看板"] },
3
+ "output": "sales.xlsx",
4
+ "operations": [
5
+ { "op": "write", "sheet": "明细", "range": "A1", "values": [["区域", "品类", "金额"], ["华东", "泵", 100], ["华东", "阀", 50], ["华北", "泵", 70], ["华南", "阀", 30]] },
6
+ { "op": "table.create", "sheet": "明细", "range": "A1:C5", "name": "销售" },
7
+ { "op": "pivot.create", "sheet": "透视", "name": "品类汇总", "cell": "A3", "source": "销售", "rows": ["品类"], "values": [{ "field": "金额", "aggregate": "sum", "name": "金额合计" }], "grandTotalCaption": "总计" },
8
+ { "op": "slicer.create", "sheet": "透视", "name": "区域切片", "pivots": [{ "sheet": "透视", "name": "品类汇总" }], "field": "区域", "anchor": { "kind": "oneCell", "from": { "cell": "E3" }, "width": 160, "height": 140 }, "caption": "区域" },
9
+ { "op": "write", "sheet": "看板", "range": "A1", "values": [["当前选择的金额合计", { "formula": "=INDEX(透视!B:B,MATCH(\"总计\",透视!A:A,0))" }], ["其中泵类", { "formula": "=IFERROR(INDEX(透视!B:B,MATCH(\"泵\",透视!A:A,0)),0)" }]] }
10
+ ]
11
+ }
@@ -0,0 +1,34 @@
1
+ // Append detail rows, refresh the pivot built on them, then walk through a
2
+ // slicer one item at a time and read the formulas that depend on the pivot
3
+ // for each selection. Finishes with the selection cleared and checks that
4
+ // the per-item values add up to the unfiltered total.
5
+ //
6
+ // Formulas downstream of a pivot are only calculated in the step that
7
+ // refreshed it: a stored pivot result from an earlier step is never passed
8
+ // off as current. So every selection reads its results inside the same step.
9
+ //
10
+ // args: { append?, pivot, slicer, items, read, total }
11
+ // append { table, columns, values } rows to add first (optional)
12
+ // pivot { sheet, name }; slicer { sheet, name }
13
+ // items slicer items to visit, in order
14
+ // read [{ sheet, range }] downstream cells to read for every selection
15
+ // total index into `read` of a single cell that is additive across items, used for the consistency check
16
+ const value = cell => cell.result?.value ?? null;
17
+ const cellsOf = step => step.result.ranges.map(range => range.cells.map(row => row.map(value)));
18
+ const must = (step, what) => { if (!step.ok) throw new Error(`${what}: ${step.error.code} ${step.error.message}`); return step; };
19
+
20
+ if (args.append) must(await wb.run({ operations: [{ op: 'table.append', ...args.append }, { op: 'pivot.refresh', ...args.pivot }] }), 'Append and refresh');
21
+
22
+ const selections = [];
23
+ for (const item of args.items) {
24
+ const step = must(await wb.run({ id: String(item), operations: [{ op: 'slicer.select', ...args.slicer, items: [item] }], read: args.read }), `Select ${item}`);
25
+ selections.push({ item, values: cellsOf(step) });
26
+ }
27
+ // Leave the workbook unfiltered, and read the same cells once more for the total.
28
+ const cleared = must(await wb.run({ id: 'all', operations: [{ op: 'slicer.select', ...args.slicer, items: null }], read: args.read }), 'Clear selection');
29
+ const all = cellsOf(cleared);
30
+
31
+ const pick = values => values[args.total][0][0];
32
+ const sum = selections.reduce((total, selection) => total + (pick(selection.values) ?? 0), 0);
33
+ if (Math.abs(sum - pick(all)) > 1e-9) throw new Error(`Per-item values add up to ${sum}, but the unfiltered total is ${pick(all)}. Is an item missing from args.items?`);
34
+ return { selections, all, sumOfItems: sum };
@@ -0,0 +1,14 @@
1
+ {
2
+ "input": "sales.xlsx",
3
+ "output": "sales-updated.xlsx",
4
+ "scriptPath": "recipe.js",
5
+ "strict": true,
6
+ "arguments": {
7
+ "append": { "table": "销售", "columns": ["区域", "品类", "金额"], "values": [["华北", "阀", 25], ["华南", "泵", 40]] },
8
+ "pivot": { "sheet": "透视", "name": "品类汇总" },
9
+ "slicer": { "sheet": "透视", "name": "区域切片" },
10
+ "items": ["华东", "华北", "华南"],
11
+ "read": [{ "sheet": "看板", "range": "B1" }, { "sheet": "看板", "range": "B2" }],
12
+ "total": 0
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ # 修复模型并选择一个情景
2
+
3
+ 在空目录生成基准、工作副本和来源模板,最终交付 `delivery.xlsx` 与 `report.json`。示例需要 Python 3;所有工作簿读取、修改和计算均由 ExcelKit 执行。
4
+
5
+ 从程序包根目录运行:
6
+
7
+ ```sh
8
+ python3 recipes/repair-and-test-model/workflow.py ./model-output --cli ./excel-kit
9
+ ```
10
+
11
+ Windows 使用 `py -3` 和 `.\excel-kit.exe`。安装在 PATH 时可省略 `--cli`。
12
+
13
+ 先比较同一矩形中的公式与输入。示例在目标会话已有未保存编辑的情况下,验证替换范围、来源绑定、当前版本,然后迁入含合并标题、费率公式和图表的区块。两个试算分别得到 36 和 54,仅提交 36。脚本再刷新条件透视指标,调高显示不全的标题行,核对汇总值后保存。报告记录了每次选择所依据的内容差异,以及调用者需要重新读取的范围和图表。