@cj-tech-master/excelts 9.2.1 → 9.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 (383) hide show
  1. package/README.md +25 -2
  2. package/README_zh.md +29 -6
  3. package/dist/browser/index.browser.d.ts +1 -1
  4. package/dist/browser/index.browser.js +4 -0
  5. package/dist/browser/index.d.ts +1 -1
  6. package/dist/browser/index.js +4 -0
  7. package/dist/browser/modules/excel/cell.d.ts +17 -3
  8. package/dist/browser/modules/excel/cell.js +170 -22
  9. package/dist/browser/modules/excel/defined-names.d.ts +96 -1
  10. package/dist/browser/modules/excel/defined-names.js +411 -21
  11. package/dist/browser/modules/excel/image.d.ts +11 -0
  12. package/dist/browser/modules/excel/image.js +24 -1
  13. package/dist/browser/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
  14. package/dist/browser/modules/excel/stream/workbook-reader.browser.js +14 -0
  15. package/dist/browser/modules/excel/stream/workbook-reader.d.ts +2 -1
  16. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
  17. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +48 -1
  18. package/dist/browser/modules/excel/stream/workbook-writer.d.ts +3 -2
  19. package/dist/browser/modules/excel/stream/worksheet-reader.js +17 -1
  20. package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +39 -6
  21. package/dist/browser/modules/excel/stream/worksheet-writer.js +45 -5
  22. package/dist/browser/modules/excel/table.js +15 -2
  23. package/dist/browser/modules/excel/types.d.ts +133 -2
  24. package/dist/browser/modules/excel/utils/col-cache.d.ts +1 -0
  25. package/dist/browser/modules/excel/utils/col-cache.js +15 -0
  26. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +3 -3
  27. package/dist/browser/modules/excel/utils/drawing-utils.js +4 -0
  28. package/dist/browser/modules/excel/utils/external-link-formula.d.ts +76 -0
  29. package/dist/browser/modules/excel/utils/external-link-formula.js +208 -0
  30. package/dist/browser/modules/excel/utils/iterate-stream.d.ts +9 -3
  31. package/dist/browser/modules/excel/utils/iterate-stream.js +3 -1
  32. package/dist/browser/modules/excel/utils/ooxml-paths.d.ts +19 -0
  33. package/dist/browser/modules/excel/utils/ooxml-paths.js +37 -2
  34. package/dist/browser/modules/excel/utils/shared-strings.d.ts +8 -3
  35. package/dist/browser/modules/excel/utils/shared-strings.js +21 -2
  36. package/dist/browser/modules/excel/utils/workbook-protection.d.ts +30 -0
  37. package/dist/browser/modules/excel/utils/workbook-protection.js +30 -0
  38. package/dist/browser/modules/excel/workbook.browser.d.ts +257 -6
  39. package/dist/browser/modules/excel/workbook.browser.js +318 -34
  40. package/dist/browser/modules/excel/workbook.d.ts +1 -1
  41. package/dist/browser/modules/excel/worksheet.d.ts +3 -1
  42. package/dist/browser/modules/excel/worksheet.js +21 -2
  43. package/dist/browser/modules/excel/xlsx/rel-type.d.ts +15 -0
  44. package/dist/browser/modules/excel/xlsx/rel-type.js +16 -1
  45. package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
  46. package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  47. package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
  48. package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
  49. package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
  50. package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
  51. package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
  52. package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  53. package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
  54. package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
  55. package/dist/browser/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  56. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
  57. package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
  58. package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
  59. package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
  60. package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
  61. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  62. package/dist/browser/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  63. package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
  64. package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  65. package/dist/browser/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  66. package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
  67. package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
  68. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  69. package/dist/browser/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  70. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
  71. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +410 -20
  72. package/dist/browser/modules/excel/xlsx/xlsx.d.ts +7 -4
  73. package/dist/browser/modules/excel/xlsx/xlsx.js +4 -5
  74. package/dist/browser/modules/formula/compile/address-utils.d.ts +62 -0
  75. package/dist/browser/modules/formula/compile/address-utils.js +83 -0
  76. package/dist/browser/modules/formula/compile/binder.d.ts +42 -0
  77. package/dist/browser/modules/formula/compile/binder.js +487 -0
  78. package/dist/browser/modules/formula/compile/bound-ast.d.ts +230 -0
  79. package/dist/browser/modules/formula/compile/bound-ast.js +80 -0
  80. package/dist/browser/modules/formula/compile/compiled-formula.d.ts +137 -0
  81. package/dist/browser/modules/formula/compile/compiled-formula.js +383 -0
  82. package/dist/browser/modules/formula/compile/dependency-analysis.d.ts +93 -0
  83. package/dist/browser/modules/formula/compile/dependency-analysis.js +432 -0
  84. package/dist/browser/modules/formula/compile/structured-ref-utils.d.ts +93 -0
  85. package/dist/browser/modules/formula/compile/structured-ref-utils.js +136 -0
  86. package/dist/browser/modules/formula/default-syntax-probe.d.ts +79 -0
  87. package/dist/browser/modules/formula/default-syntax-probe.js +83 -0
  88. package/dist/browser/modules/formula/functions/_date-context.d.ts +4 -0
  89. package/dist/browser/modules/formula/functions/_date-context.js +29 -0
  90. package/dist/browser/modules/formula/functions/_shared.d.ts +121 -0
  91. package/dist/browser/modules/formula/functions/_shared.js +381 -0
  92. package/dist/browser/modules/formula/functions/conditional.d.ts +27 -0
  93. package/dist/browser/modules/formula/functions/conditional.js +343 -0
  94. package/dist/browser/modules/formula/functions/database.d.ts +37 -0
  95. package/dist/browser/modules/formula/functions/database.js +274 -0
  96. package/dist/browser/modules/formula/functions/date.d.ts +61 -0
  97. package/dist/browser/modules/formula/functions/date.js +855 -0
  98. package/dist/browser/modules/formula/functions/dynamic-array.d.ts +23 -0
  99. package/dist/browser/modules/formula/functions/dynamic-array.js +860 -0
  100. package/dist/browser/modules/formula/functions/engineering.d.ts +57 -0
  101. package/dist/browser/modules/formula/functions/engineering.js +1128 -0
  102. package/dist/browser/modules/formula/functions/financial.d.ts +202 -0
  103. package/dist/browser/modules/formula/functions/financial.js +2296 -0
  104. package/dist/browser/modules/formula/functions/lookup.d.ts +18 -0
  105. package/dist/browser/modules/formula/functions/lookup.js +886 -0
  106. package/dist/browser/modules/formula/functions/math.d.ts +114 -0
  107. package/dist/browser/modules/formula/functions/math.js +1406 -0
  108. package/dist/browser/modules/formula/functions/statistical.d.ts +193 -0
  109. package/dist/browser/modules/formula/functions/statistical.js +3390 -0
  110. package/dist/browser/modules/formula/functions/text.d.ts +86 -0
  111. package/dist/browser/modules/formula/functions/text.js +1845 -0
  112. package/dist/browser/modules/formula/host-registry.d.ts +53 -0
  113. package/dist/browser/modules/formula/host-registry.js +69 -0
  114. package/dist/browser/modules/formula/index.d.ts +39 -0
  115. package/dist/browser/modules/formula/index.js +49 -0
  116. package/dist/browser/modules/formula/install.d.ts +62 -0
  117. package/dist/browser/modules/formula/install.js +88 -0
  118. package/dist/browser/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
  119. package/dist/browser/modules/formula/integration/apply-writeback-plan.js +210 -0
  120. package/dist/browser/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
  121. package/dist/browser/modules/formula/integration/calculate-formulas-impl.js +616 -0
  122. package/dist/browser/modules/formula/integration/calculate-formulas.d.ts +67 -0
  123. package/dist/browser/modules/formula/integration/calculate-formulas.js +68 -0
  124. package/dist/browser/modules/formula/integration/formula-instance.d.ts +64 -0
  125. package/dist/browser/modules/formula/integration/formula-instance.js +79 -0
  126. package/dist/browser/modules/formula/integration/workbook-adapter.d.ts +26 -0
  127. package/dist/browser/modules/formula/integration/workbook-adapter.js +324 -0
  128. package/dist/browser/modules/formula/integration/workbook-snapshot.d.ts +267 -0
  129. package/dist/browser/modules/formula/integration/workbook-snapshot.js +77 -0
  130. package/dist/browser/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
  131. package/dist/browser/modules/formula/materialize/build-writeback-plan.js +473 -0
  132. package/dist/browser/modules/formula/materialize/spill-engine.d.ts +9 -0
  133. package/dist/browser/modules/formula/materialize/spill-engine.js +38 -0
  134. package/dist/browser/modules/formula/materialize/types.d.ts +179 -0
  135. package/dist/browser/modules/formula/materialize/types.js +29 -0
  136. package/dist/browser/modules/formula/materialize/writeback-plan.d.ts +167 -0
  137. package/dist/browser/modules/formula/materialize/writeback-plan.js +27 -0
  138. package/dist/browser/modules/formula/runtime/evaluator.d.ts +151 -0
  139. package/dist/browser/modules/formula/runtime/evaluator.js +2291 -0
  140. package/dist/browser/modules/formula/runtime/function-registry.d.ts +47 -0
  141. package/dist/browser/modules/formula/runtime/function-registry.js +840 -0
  142. package/dist/browser/modules/formula/runtime/values.d.ts +211 -0
  143. package/dist/browser/modules/formula/runtime/values.js +385 -0
  144. package/dist/browser/modules/formula/syntax/ast.d.ts +129 -0
  145. package/dist/browser/modules/formula/syntax/ast.js +28 -0
  146. package/dist/browser/modules/formula/syntax/parser.d.ts +18 -0
  147. package/dist/browser/modules/formula/syntax/parser.js +439 -0
  148. package/dist/browser/modules/formula/syntax/token-types.d.ts +153 -0
  149. package/dist/browser/modules/formula/syntax/token-types.js +59 -0
  150. package/dist/browser/modules/formula/syntax/tokenizer.d.ts +10 -0
  151. package/dist/browser/modules/formula/syntax/tokenizer.js +1074 -0
  152. package/dist/browser/modules/pdf/excel-bridge.js +9 -0
  153. package/dist/cjs/index.js +4 -0
  154. package/dist/cjs/modules/excel/cell.js +170 -22
  155. package/dist/cjs/modules/excel/defined-names.js +411 -21
  156. package/dist/cjs/modules/excel/image.js +24 -1
  157. package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +14 -0
  158. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +48 -1
  159. package/dist/cjs/modules/excel/stream/worksheet-reader.js +17 -1
  160. package/dist/cjs/modules/excel/stream/worksheet-writer.js +45 -5
  161. package/dist/cjs/modules/excel/table.js +15 -2
  162. package/dist/cjs/modules/excel/utils/col-cache.js +15 -0
  163. package/dist/cjs/modules/excel/utils/drawing-utils.js +4 -0
  164. package/dist/cjs/modules/excel/utils/external-link-formula.js +212 -0
  165. package/dist/cjs/modules/excel/utils/iterate-stream.js +3 -1
  166. package/dist/cjs/modules/excel/utils/ooxml-paths.js +42 -2
  167. package/dist/cjs/modules/excel/utils/shared-strings.js +21 -2
  168. package/dist/cjs/modules/excel/utils/workbook-protection.js +33 -0
  169. package/dist/cjs/modules/excel/workbook.browser.js +318 -34
  170. package/dist/cjs/modules/excel/worksheet.js +20 -1
  171. package/dist/cjs/modules/excel/xlsx/rel-type.js +16 -1
  172. package/dist/cjs/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  173. package/dist/cjs/modules/excel/xlsx/xform/book/external-link-xform.js +333 -0
  174. package/dist/cjs/modules/excel/xlsx/xform/book/external-reference-xform.js +27 -0
  175. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  176. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-protection-xform.js +69 -0
  177. package/dist/cjs/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  178. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +18 -0
  179. package/dist/cjs/modules/excel/xlsx/xform/core/metadata-xform.js +161 -0
  180. package/dist/cjs/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +108 -0
  181. package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  182. package/dist/cjs/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  183. package/dist/cjs/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  184. package/dist/cjs/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  185. package/dist/cjs/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +83 -0
  186. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  187. package/dist/cjs/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  188. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +408 -18
  189. package/dist/cjs/modules/excel/xlsx/xlsx.js +4 -5
  190. package/dist/cjs/modules/formula/compile/address-utils.js +89 -0
  191. package/dist/cjs/modules/formula/compile/binder.js +489 -0
  192. package/dist/cjs/modules/formula/compile/bound-ast.js +68 -0
  193. package/dist/cjs/modules/formula/compile/compiled-formula.js +387 -0
  194. package/dist/cjs/modules/formula/compile/dependency-analysis.js +437 -0
  195. package/dist/cjs/modules/formula/compile/structured-ref-utils.js +141 -0
  196. package/dist/cjs/modules/formula/default-syntax-probe.js +87 -0
  197. package/dist/cjs/modules/formula/functions/_date-context.js +33 -0
  198. package/dist/cjs/modules/formula/functions/_shared.js +396 -0
  199. package/dist/cjs/modules/formula/functions/conditional.js +354 -0
  200. package/dist/cjs/modules/formula/functions/database.js +288 -0
  201. package/dist/cjs/modules/formula/functions/date.js +883 -0
  202. package/dist/cjs/modules/formula/functions/dynamic-array.js +881 -0
  203. package/dist/cjs/modules/formula/functions/engineering.js +1183 -0
  204. package/dist/cjs/modules/formula/functions/financial.js +2348 -0
  205. package/dist/cjs/modules/formula/functions/lookup.js +902 -0
  206. package/dist/cjs/modules/formula/functions/math.js +1487 -0
  207. package/dist/cjs/modules/formula/functions/statistical.js +3488 -0
  208. package/dist/cjs/modules/formula/functions/text.js +1889 -0
  209. package/dist/cjs/modules/formula/host-registry.js +75 -0
  210. package/dist/cjs/modules/formula/index.js +58 -0
  211. package/dist/cjs/modules/formula/install.js +93 -0
  212. package/dist/cjs/modules/formula/integration/apply-writeback-plan.js +213 -0
  213. package/dist/cjs/modules/formula/integration/calculate-formulas-impl.js +619 -0
  214. package/dist/cjs/modules/formula/integration/calculate-formulas.js +71 -0
  215. package/dist/cjs/modules/formula/integration/formula-instance.js +82 -0
  216. package/dist/cjs/modules/formula/integration/workbook-adapter.js +327 -0
  217. package/dist/cjs/modules/formula/integration/workbook-snapshot.js +84 -0
  218. package/dist/cjs/modules/formula/materialize/build-writeback-plan.js +475 -0
  219. package/dist/cjs/modules/formula/materialize/spill-engine.js +42 -0
  220. package/dist/cjs/modules/formula/materialize/types.js +32 -0
  221. package/dist/cjs/modules/formula/materialize/writeback-plan.js +28 -0
  222. package/dist/cjs/modules/formula/runtime/evaluator.js +2298 -0
  223. package/dist/cjs/modules/formula/runtime/function-registry.js +846 -0
  224. package/dist/cjs/modules/formula/runtime/values.js +385 -0
  225. package/dist/cjs/modules/formula/syntax/ast.js +8 -0
  226. package/dist/cjs/modules/formula/syntax/parser.js +440 -0
  227. package/dist/cjs/modules/formula/syntax/token-types.js +32 -0
  228. package/dist/cjs/modules/formula/syntax/tokenizer.js +1076 -0
  229. package/dist/cjs/modules/pdf/excel-bridge.js +9 -0
  230. package/dist/esm/index.browser.js +4 -0
  231. package/dist/esm/index.js +4 -0
  232. package/dist/esm/modules/excel/cell.js +170 -22
  233. package/dist/esm/modules/excel/defined-names.js +411 -21
  234. package/dist/esm/modules/excel/image.js +24 -1
  235. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +14 -0
  236. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +48 -1
  237. package/dist/esm/modules/excel/stream/worksheet-reader.js +17 -1
  238. package/dist/esm/modules/excel/stream/worksheet-writer.js +45 -5
  239. package/dist/esm/modules/excel/table.js +15 -2
  240. package/dist/esm/modules/excel/utils/col-cache.js +15 -0
  241. package/dist/esm/modules/excel/utils/drawing-utils.js +4 -0
  242. package/dist/esm/modules/excel/utils/external-link-formula.js +208 -0
  243. package/dist/esm/modules/excel/utils/iterate-stream.js +3 -1
  244. package/dist/esm/modules/excel/utils/ooxml-paths.js +37 -2
  245. package/dist/esm/modules/excel/utils/shared-strings.js +21 -2
  246. package/dist/esm/modules/excel/utils/workbook-protection.js +30 -0
  247. package/dist/esm/modules/excel/workbook.browser.js +318 -34
  248. package/dist/esm/modules/excel/worksheet.js +21 -2
  249. package/dist/esm/modules/excel/xlsx/rel-type.js +16 -1
  250. package/dist/esm/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
  251. package/dist/esm/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
  252. package/dist/esm/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
  253. package/dist/esm/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
  254. package/dist/esm/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
  255. package/dist/esm/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
  256. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
  257. package/dist/esm/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
  258. package/dist/esm/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
  259. package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
  260. package/dist/esm/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
  261. package/dist/esm/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
  262. package/dist/esm/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
  263. package/dist/esm/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
  264. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
  265. package/dist/esm/modules/excel/xlsx/xform/style/border-xform.js +4 -1
  266. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +410 -20
  267. package/dist/esm/modules/excel/xlsx/xlsx.js +4 -5
  268. package/dist/esm/modules/formula/compile/address-utils.js +83 -0
  269. package/dist/esm/modules/formula/compile/binder.js +487 -0
  270. package/dist/esm/modules/formula/compile/bound-ast.js +80 -0
  271. package/dist/esm/modules/formula/compile/compiled-formula.js +383 -0
  272. package/dist/esm/modules/formula/compile/dependency-analysis.js +432 -0
  273. package/dist/esm/modules/formula/compile/structured-ref-utils.js +136 -0
  274. package/dist/esm/modules/formula/default-syntax-probe.js +83 -0
  275. package/dist/esm/modules/formula/functions/_date-context.js +29 -0
  276. package/dist/esm/modules/formula/functions/_shared.js +381 -0
  277. package/dist/esm/modules/formula/functions/conditional.js +343 -0
  278. package/dist/esm/modules/formula/functions/database.js +274 -0
  279. package/dist/esm/modules/formula/functions/date.js +855 -0
  280. package/dist/esm/modules/formula/functions/dynamic-array.js +860 -0
  281. package/dist/esm/modules/formula/functions/engineering.js +1128 -0
  282. package/dist/esm/modules/formula/functions/financial.js +2296 -0
  283. package/dist/esm/modules/formula/functions/lookup.js +886 -0
  284. package/dist/esm/modules/formula/functions/math.js +1406 -0
  285. package/dist/esm/modules/formula/functions/statistical.js +3390 -0
  286. package/dist/esm/modules/formula/functions/text.js +1845 -0
  287. package/dist/esm/modules/formula/host-registry.js +69 -0
  288. package/dist/esm/modules/formula/index.js +49 -0
  289. package/dist/esm/modules/formula/install.js +88 -0
  290. package/dist/esm/modules/formula/integration/apply-writeback-plan.js +210 -0
  291. package/dist/esm/modules/formula/integration/calculate-formulas-impl.js +616 -0
  292. package/dist/esm/modules/formula/integration/calculate-formulas.js +68 -0
  293. package/dist/esm/modules/formula/integration/formula-instance.js +79 -0
  294. package/dist/esm/modules/formula/integration/workbook-adapter.js +324 -0
  295. package/dist/esm/modules/formula/integration/workbook-snapshot.js +77 -0
  296. package/dist/esm/modules/formula/materialize/build-writeback-plan.js +473 -0
  297. package/dist/esm/modules/formula/materialize/spill-engine.js +38 -0
  298. package/dist/esm/modules/formula/materialize/types.js +29 -0
  299. package/dist/esm/modules/formula/materialize/writeback-plan.js +27 -0
  300. package/dist/esm/modules/formula/runtime/evaluator.js +2291 -0
  301. package/dist/esm/modules/formula/runtime/function-registry.js +840 -0
  302. package/dist/esm/modules/formula/runtime/values.js +385 -0
  303. package/dist/esm/modules/formula/syntax/ast.js +28 -0
  304. package/dist/esm/modules/formula/syntax/parser.js +439 -0
  305. package/dist/esm/modules/formula/syntax/token-types.js +59 -0
  306. package/dist/esm/modules/formula/syntax/tokenizer.js +1074 -0
  307. package/dist/esm/modules/pdf/excel-bridge.js +9 -0
  308. package/dist/iife/excelts.iife.js +2302 -373
  309. package/dist/iife/excelts.iife.js.map +1 -1
  310. package/dist/iife/excelts.iife.min.js +34 -34
  311. package/dist/types/index.browser.d.ts +1 -1
  312. package/dist/types/index.d.ts +1 -1
  313. package/dist/types/modules/excel/cell.d.ts +17 -3
  314. package/dist/types/modules/excel/defined-names.d.ts +96 -1
  315. package/dist/types/modules/excel/image.d.ts +11 -0
  316. package/dist/types/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
  317. package/dist/types/modules/excel/stream/workbook-reader.d.ts +2 -1
  318. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
  319. package/dist/types/modules/excel/stream/workbook-writer.d.ts +3 -2
  320. package/dist/types/modules/excel/stream/worksheet-writer.d.ts +39 -6
  321. package/dist/types/modules/excel/types.d.ts +133 -2
  322. package/dist/types/modules/excel/utils/col-cache.d.ts +1 -0
  323. package/dist/types/modules/excel/utils/drawing-utils.d.ts +3 -3
  324. package/dist/types/modules/excel/utils/external-link-formula.d.ts +76 -0
  325. package/dist/types/modules/excel/utils/iterate-stream.d.ts +9 -3
  326. package/dist/types/modules/excel/utils/ooxml-paths.d.ts +19 -0
  327. package/dist/types/modules/excel/utils/shared-strings.d.ts +8 -3
  328. package/dist/types/modules/excel/utils/workbook-protection.d.ts +30 -0
  329. package/dist/types/modules/excel/workbook.browser.d.ts +257 -6
  330. package/dist/types/modules/excel/workbook.d.ts +1 -1
  331. package/dist/types/modules/excel/worksheet.d.ts +3 -1
  332. package/dist/types/modules/excel/xlsx/rel-type.d.ts +15 -0
  333. package/dist/types/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
  334. package/dist/types/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
  335. package/dist/types/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
  336. package/dist/types/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
  337. package/dist/types/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
  338. package/dist/types/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
  339. package/dist/types/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
  340. package/dist/types/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
  341. package/dist/types/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
  342. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
  343. package/dist/types/modules/excel/xlsx/xlsx.d.ts +7 -4
  344. package/dist/types/modules/formula/compile/address-utils.d.ts +62 -0
  345. package/dist/types/modules/formula/compile/binder.d.ts +42 -0
  346. package/dist/types/modules/formula/compile/bound-ast.d.ts +230 -0
  347. package/dist/types/modules/formula/compile/compiled-formula.d.ts +137 -0
  348. package/dist/types/modules/formula/compile/dependency-analysis.d.ts +93 -0
  349. package/dist/types/modules/formula/compile/structured-ref-utils.d.ts +93 -0
  350. package/dist/types/modules/formula/default-syntax-probe.d.ts +79 -0
  351. package/dist/types/modules/formula/functions/_date-context.d.ts +4 -0
  352. package/dist/types/modules/formula/functions/_shared.d.ts +121 -0
  353. package/dist/types/modules/formula/functions/conditional.d.ts +27 -0
  354. package/dist/types/modules/formula/functions/database.d.ts +37 -0
  355. package/dist/types/modules/formula/functions/date.d.ts +61 -0
  356. package/dist/types/modules/formula/functions/dynamic-array.d.ts +23 -0
  357. package/dist/types/modules/formula/functions/engineering.d.ts +57 -0
  358. package/dist/types/modules/formula/functions/financial.d.ts +202 -0
  359. package/dist/types/modules/formula/functions/lookup.d.ts +18 -0
  360. package/dist/types/modules/formula/functions/math.d.ts +114 -0
  361. package/dist/types/modules/formula/functions/statistical.d.ts +193 -0
  362. package/dist/types/modules/formula/functions/text.d.ts +86 -0
  363. package/dist/types/modules/formula/host-registry.d.ts +53 -0
  364. package/dist/types/modules/formula/index.d.ts +39 -0
  365. package/dist/types/modules/formula/install.d.ts +62 -0
  366. package/dist/types/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
  367. package/dist/types/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
  368. package/dist/types/modules/formula/integration/calculate-formulas.d.ts +67 -0
  369. package/dist/types/modules/formula/integration/formula-instance.d.ts +64 -0
  370. package/dist/types/modules/formula/integration/workbook-adapter.d.ts +26 -0
  371. package/dist/types/modules/formula/integration/workbook-snapshot.d.ts +267 -0
  372. package/dist/types/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
  373. package/dist/types/modules/formula/materialize/spill-engine.d.ts +9 -0
  374. package/dist/types/modules/formula/materialize/types.d.ts +179 -0
  375. package/dist/types/modules/formula/materialize/writeback-plan.d.ts +167 -0
  376. package/dist/types/modules/formula/runtime/evaluator.d.ts +151 -0
  377. package/dist/types/modules/formula/runtime/function-registry.d.ts +47 -0
  378. package/dist/types/modules/formula/runtime/values.d.ts +211 -0
  379. package/dist/types/modules/formula/syntax/ast.d.ts +129 -0
  380. package/dist/types/modules/formula/syntax/parser.d.ts +18 -0
  381. package/dist/types/modules/formula/syntax/token-types.d.ts +153 -0
  382. package/dist/types/modules/formula/syntax/tokenizer.d.ts +10 -0
  383. package/package.json +28 -28
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Formula Engine Registry
4
+ *
5
+ * A tiny indirection layer that lets `Workbook.calculateFormulas()` and
6
+ * the PDF bridge invoke a full formula engine **only if the host
7
+ * application has opted in** by calling `installFormulaEngine()` from
8
+ * `@cj-tech-master/excelts/formula`.
9
+ *
10
+ * ## Why a registry
11
+ *
12
+ * The formula engine ships 433 Excel functions, a tokenizer, a parser,
13
+ * a compiler, an evaluator, a dependency graph and a spill materialiser.
14
+ * Minified this is ~200 KB. Most Workbook users only need to read /
15
+ * write XLSX files and let Excel recalculate on open; pulling the
16
+ * engine into their bundle unconditionally would be a large, invisible
17
+ * cost.
18
+ *
19
+ * This file is the single point of indirection. Importing `Workbook`
20
+ * pulls it in (~2.5 KB) but does NOT pull in the engine; the engine's
21
+ * implementation only arrives once someone calls `installFormulaEngine()`,
22
+ * which bundlers can then resolve to the subpath import graph.
23
+ *
24
+ * If `calculateFormulas()` is called without `installFormulaEngine()`
25
+ * having run, a clear error is thrown telling the developer how to fix it.
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.registerFormulaEngine = registerFormulaEngine;
29
+ exports.hasFormulaEngine = hasFormulaEngine;
30
+ exports.invokeFormulaEngine = invokeFormulaEngine;
31
+ exports.tryInvokeFormulaEngine = tryInvokeFormulaEngine;
32
+ let installed = null;
33
+ /**
34
+ * Install a formula engine implementation. Called from
35
+ * `installFormulaEngine()` in the `@cj-tech-master/excelts/formula`
36
+ * subpath.
37
+ *
38
+ * Re-installing is allowed — the last registration wins. This keeps
39
+ * hot-reload tooling and tests simple. Passing `null` uninstalls the
40
+ * engine, which is useful for tests that exercise the
41
+ * "no engine" error path.
42
+ */
43
+ function registerFormulaEngine(engine) {
44
+ installed = engine;
45
+ }
46
+ /** Returns true when a formula engine has been installed. */
47
+ function hasFormulaEngine() {
48
+ return installed !== null;
49
+ }
50
+ /**
51
+ * Invoke the registered engine on `workbook`. Throws a descriptive error
52
+ * if no engine has been installed.
53
+ */
54
+ function invokeFormulaEngine(workbook) {
55
+ if (!installed) {
56
+ throw new Error("No formula engine is installed. " +
57
+ "Call `installFormulaEngine()` from `@cj-tech-master/excelts/formula` " +
58
+ "once at startup to enable `Workbook.calculateFormulas()` and " +
59
+ "automatic recalculation during `excelToPdf()`.");
60
+ }
61
+ installed(workbook);
62
+ }
63
+ /**
64
+ * Like {@link invokeFormulaEngine} but returns silently when no engine is
65
+ * installed. Used by `excelToPdf()` so that PDF export still works for
66
+ * workbooks whose cached formula results are already up to date (the
67
+ * common case when the XLSX was saved by Excel itself).
68
+ */
69
+ function tryInvokeFormulaEngine(workbook) {
70
+ if (!installed) {
71
+ return false;
72
+ }
73
+ installed(workbook);
74
+ return true;
75
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /**
3
+ * Public entry for the excelts formula engine.
4
+ *
5
+ * Two complementary usage styles are supported:
6
+ *
7
+ * 1. **Functional, zero-side-effect**:
8
+ * ```ts
9
+ * import { calculateFormulas } from "@cj-tech-master/excelts/formula";
10
+ * calculateFormulas(workbook);
11
+ * ```
12
+ * Perfect tree-shaking: unused exports are dropped, no module
13
+ * initialisation runs. Bundles that import only `tokenize` or
14
+ * `parse` never pull the evaluator or function registry in.
15
+ *
16
+ * 2. **Engine installation**, to enable `Workbook.calculateFormulas()`
17
+ * and automatic recalculation in `excelToPdf()`:
18
+ * ```ts
19
+ * import { installFormulaEngine } from "@cj-tech-master/excelts/formula";
20
+ * installFormulaEngine(); // once, at startup
21
+ * workbook.calculateFormulas(); // now works
22
+ * ```
23
+ *
24
+ * The engine is **never installed implicitly** — consumers pay for what
25
+ * they ask for. This keeps the root `package.json` `sideEffects: false`
26
+ * contract intact, so bundles that only use the functional API include
27
+ * exactly the code paths reachable from the exports they reference.
28
+ *
29
+ * Note: `installFormulaEngine` lives in a separate module
30
+ * (`./install.ts`) so that its host-registry import and the
31
+ * evaluator pipeline it carries don't get pulled in by consumers who
32
+ * only need the tokenizer, parser, or the functional `calculateFormulas`
33
+ * API. See `scripts/treeshake-verify.ts` for the bundler contracts.
34
+ */
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.uninstallFormulaEngine = exports.installFormulaEngine = exports.createFormulaSyntaxProbe = exports.parse = exports.tokenize = exports.calculateFormulas = void 0;
37
+ // Functional API — same capability exposed as a callable rather than
38
+ // going through `Workbook.calculateFormulas()`. Useful for server-side
39
+ // recalculation of cached XLSX files loaded via the excel module.
40
+ var calculate_formulas_1 = require("./integration/calculate-formulas");
41
+ Object.defineProperty(exports, "calculateFormulas", { enumerable: true, get: function () { return calculate_formulas_1.calculateFormulas; } });
42
+ // Low-level syntax surface — for tooling, static analysers and callers
43
+ // that want to pre-validate formulas without evaluating them.
44
+ var tokenizer_1 = require("./syntax/tokenizer");
45
+ Object.defineProperty(exports, "tokenize", { enumerable: true, get: function () { return tokenizer_1.tokenize; } });
46
+ var parser_1 = require("./syntax/parser");
47
+ Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parser_1.parse; } });
48
+ // Engine installer — isolated module so its imports don't leak into
49
+ // functional-only consumers. `createFormulaSyntaxProbe` is exported for
50
+ // callers that want a standalone probe (e.g. for per-Workbook injection
51
+ // via `new Workbook({ formulaSyntaxProbe })`) without touching
52
+ // process-global state. `uninstallFormulaEngine` is exported for
53
+ // symmetry and for test suites that exercise the cold-start
54
+ // classification path.
55
+ var install_1 = require("./install");
56
+ Object.defineProperty(exports, "createFormulaSyntaxProbe", { enumerable: true, get: function () { return install_1.createFormulaSyntaxProbe; } });
57
+ Object.defineProperty(exports, "installFormulaEngine", { enumerable: true, get: function () { return install_1.installFormulaEngine; } });
58
+ Object.defineProperty(exports, "uninstallFormulaEngine", { enumerable: true, get: function () { return install_1.uninstallFormulaEngine; } });
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * Opt-in engine installer.
4
+ *
5
+ * This file carries the imports that wire a concrete formula engine and
6
+ * a tokenizer+parser probe into the excel host. Keep these imports
7
+ * isolated in a separate module so callers who import only the
8
+ * tokenizer, parser, or the functional `calculateFormulas` API from
9
+ * `./index` never trigger this module — and its evaluator + function
10
+ * registry — at bundle time.
11
+ *
12
+ * Two process-wide slots are populated:
13
+ *
14
+ * 1. The formula-engine slot (`@formula/host-registry`) — enables
15
+ * `Workbook.calculateFormulas()` and the PDF bridge's automatic
16
+ * recalculation.
17
+ *
18
+ * 2. The default syntax-probe slot (`@excel/default-syntax-probe`) —
19
+ * enables strict classification of defined-name text (formula vs.
20
+ * opaque) during XLSX load. Without this, `DefinedNames` preserves
21
+ * unrecognised text verbatim as opaque, which is correct for
22
+ * round-trip but cannot evaluate.
23
+ *
24
+ * Both slots accept `null` to uninstall. See `createFormulaSyntaxProbe`
25
+ * for constructing a probe without touching the process-global slot
26
+ * (useful for tests and for per-Workbook injection via
27
+ * `new Workbook({ formulaSyntaxProbe })`).
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.createFormulaSyntaxProbe = createFormulaSyntaxProbe;
31
+ exports.installFormulaEngine = installFormulaEngine;
32
+ exports.uninstallFormulaEngine = uninstallFormulaEngine;
33
+ const default_syntax_probe_1 = require("./default-syntax-probe");
34
+ const host_registry_1 = require("./host-registry");
35
+ const calculate_formulas_1 = require("./integration/calculate-formulas");
36
+ const parser_1 = require("./syntax/parser");
37
+ const tokenizer_1 = require("./syntax/tokenizer");
38
+ /**
39
+ * Build a standalone formula-syntax probe backed by the real
40
+ * tokenizer+parser. The returned function reports whether its argument
41
+ * parses as a formula expression.
42
+ *
43
+ * Unlike {@link installFormulaEngine}, calling this does **not** touch
44
+ * any process-global state. Inject the returned probe explicitly via
45
+ * `new Workbook({ formulaSyntaxProbe })` or `new DefinedNames(probe)`
46
+ * for deterministic, instance-scoped behaviour.
47
+ */
48
+ function createFormulaSyntaxProbe() {
49
+ return (text) => {
50
+ try {
51
+ const tokens = (0, tokenizer_1.tokenize)(text);
52
+ if (tokens.length === 0) {
53
+ return false;
54
+ }
55
+ (0, parser_1.parse)(tokens);
56
+ return true;
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ };
62
+ }
63
+ /**
64
+ * Install the formula engine and the default syntax probe into the
65
+ * excel host.
66
+ *
67
+ * After calling this once, `Workbook.calculateFormulas()` and the PDF
68
+ * bridge's automatic recalculation run the full 433-function engine
69
+ * instead of throwing / using stale cached values, and every
70
+ * subsequently-loaded workbook's defined-name classification uses the
71
+ * real tokenizer+parser instead of the conservative "opaque" fallback.
72
+ *
73
+ * Safe to call more than once — the registry accepts the last
74
+ * registration.
75
+ */
76
+ function installFormulaEngine() {
77
+ (0, host_registry_1.registerFormulaEngine)(wb => {
78
+ (0, calculate_formulas_1.calculateFormulas)(wb);
79
+ });
80
+ (0, default_syntax_probe_1.setDefaultSyntaxProbe)(createFormulaSyntaxProbe());
81
+ }
82
+ /**
83
+ * Uninstall both slots, restoring the cold-start state.
84
+ *
85
+ * Mainly useful for tests that need to exercise the "no engine" /
86
+ * "no probe" classification path. In production, calling this is
87
+ * rarely necessary — subsequent `installFormulaEngine()` calls simply
88
+ * overwrite the previous registration.
89
+ */
90
+ function uninstallFormulaEngine() {
91
+ (0, host_registry_1.registerFormulaEngine)(null);
92
+ (0, default_syntax_probe_1.setDefaultSyntaxProbe)(null);
93
+ }
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * Apply Writeback Plan — Write formula results back to the live workbook.
4
+ *
5
+ * This is the **only** file that mutates live workbook/cell objects in the
6
+ * new engine pipeline. It reads a `WritebackPlan` and applies each operation
7
+ * to the workbook.
8
+ *
9
+ * ## Responsibilities
10
+ *
11
+ * 1. Apply `ScalarWrite` → set `cell.result`.
12
+ * 2. Apply `CSEWrite` → distribute array across CSE range, update session cache.
13
+ * 3. Apply `SpillWrite` → write source + ghost cells, update persistent maps.
14
+ * 4. Apply `SpillErrorWrite` → set #SPILL! on source cell.
15
+ * 5. Apply `CleanupWrite` → clear stale ghost cells.
16
+ * 6. Apply `PreserveWrite` → no-op (cell keeps existing result).
17
+ * 7. Update persistent spill maps and ghost snapshot maps.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.applyWritebackPlan = applyWritebackPlan;
21
+ const spill_engine_1 = require("../materialize/spill-engine");
22
+ const types_1 = require("../materialize/types");
23
+ // ============================================================================
24
+ // Apply Writeback Plan
25
+ // ============================================================================
26
+ /**
27
+ * Apply a `WritebackPlan` to a live workbook.
28
+ *
29
+ * This mutates the workbook in-place. Operations are applied in order.
30
+ * After all operations, persistent spill metadata is updated.
31
+ */
32
+ function applyWritebackPlan(workbook, plan) {
33
+ // Apply each operation
34
+ for (const op of plan.operations) {
35
+ applyOperation(workbook, op);
36
+ }
37
+ // Update persistent spill metadata
38
+ const persistentSpills = (0, spill_engine_1.getPersistentSpillMap)(workbook);
39
+ const ghostSnapshots = (0, spill_engine_1.getGhostSnapshots)(workbook);
40
+ // Remove stale spill entries
41
+ for (const key of plan.spillState.removedSpillKeys) {
42
+ persistentSpills.delete(key);
43
+ }
44
+ // Update spill regions
45
+ for (const [key, region] of plan.spillState.spillRegions) {
46
+ persistentSpills.set(key, region);
47
+ }
48
+ // Update ghost value snapshots
49
+ for (const [key, value] of plan.spillState.ghostSnapshots) {
50
+ ghostSnapshots.set(key, snapshotValueToRaw(value));
51
+ }
52
+ }
53
+ // ============================================================================
54
+ // Apply Individual Operations
55
+ // ============================================================================
56
+ function applyOperation(workbook, op) {
57
+ switch (op.type) {
58
+ case "scalar":
59
+ applyScalarWrite(workbook, op);
60
+ break;
61
+ case "cse":
62
+ applyCSEWrite(workbook, op);
63
+ break;
64
+ case "spill":
65
+ applySpillWrite(workbook, op);
66
+ break;
67
+ case "spill-error":
68
+ applySpillErrorWrite(workbook, op);
69
+ break;
70
+ case "cleanup":
71
+ applyCleanupWrite(workbook, op);
72
+ break;
73
+ case "preserve":
74
+ // No-op: keep existing cached result
75
+ break;
76
+ }
77
+ }
78
+ function applyScalarWrite(workbook, op) {
79
+ const ws = workbook.getWorksheet(op.sheetName);
80
+ if (!ws) {
81
+ return;
82
+ }
83
+ const cell = ws.findCell(op.row, op.col);
84
+ if (!cell) {
85
+ return;
86
+ }
87
+ cell.result = snapshotValueToResult(op.value);
88
+ }
89
+ function applyCSEWrite(workbook, op) {
90
+ const ws = workbook.getWorksheet(op.sheetName);
91
+ if (!ws) {
92
+ return;
93
+ }
94
+ const numRows = op.bottom - op.top + 1;
95
+ const numCols = op.right - op.left + 1;
96
+ for (let r = 0; r < numRows; r++) {
97
+ for (let c = 0; c < numCols; c++) {
98
+ const targetRow = op.top + r;
99
+ const targetCol = op.left + c;
100
+ // Use `findCell` (non-creating) rather than `getCell`. Only cells
101
+ // that are already CSE array slaves — i.e., existing formula cells
102
+ // sharing the master's array `ref` — receive results. Calling
103
+ // `getCell` would lazily materialise every blank position in the
104
+ // target range, which for a 1000×1000 CSE region would bloat the
105
+ // workbook with a million empty cells (and force every subsequent
106
+ // row iterator to walk them). The type check on the next line
107
+ // already implied this intent; we now match it with a matching
108
+ // lookup that has no side effects.
109
+ const targetCell = ws.findCell(targetRow, targetCol);
110
+ if (targetCell && targetCell.type === types_1.CellValueTypeLike.Formula) {
111
+ if (op.scalarFill !== undefined) {
112
+ targetCell.result = snapshotValueToResult(op.scalarFill);
113
+ }
114
+ else {
115
+ const val = op.results[r]?.[c] ?? null;
116
+ targetCell.result = snapshotValueToResult(val);
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ function applySpillWrite(workbook, op) {
123
+ const ws = workbook.getWorksheet(op.sheetName);
124
+ if (!ws) {
125
+ return;
126
+ }
127
+ const numRows = op.results.length;
128
+ const numCols = op.results[0]?.length ?? 0;
129
+ for (let r = 0; r < numRows; r++) {
130
+ for (let c = 0; c < numCols; c++) {
131
+ const targetRow = op.row + r;
132
+ const targetCol = op.col + c;
133
+ const val = op.results[r]?.[c] ?? null;
134
+ if (r === 0 && c === 0) {
135
+ // Source cell: set result
136
+ const sourceCell = ws.findCell(targetRow, targetCol);
137
+ if (sourceCell) {
138
+ sourceCell.result = snapshotValueToResult(val);
139
+ }
140
+ }
141
+ else {
142
+ // Ghost cell: set value (not result)
143
+ const targetCell = ws.getCell(targetRow, targetCol);
144
+ targetCell.value = snapshotValueToRaw(val);
145
+ }
146
+ }
147
+ }
148
+ }
149
+ function applySpillErrorWrite(workbook, op) {
150
+ const ws = workbook.getWorksheet(op.sheetName);
151
+ if (!ws) {
152
+ return;
153
+ }
154
+ const cell = ws.findCell(op.row, op.col);
155
+ if (cell) {
156
+ cell.result = { error: "#SPILL!" };
157
+ }
158
+ }
159
+ function applyCleanupWrite(workbook, op) {
160
+ const ws = workbook.getWorksheet(op.sheetName);
161
+ if (!ws) {
162
+ return;
163
+ }
164
+ for (const { row, col } of op.cells) {
165
+ const cell = ws.findCell(row, col);
166
+ if (cell) {
167
+ cell.value = null;
168
+ }
169
+ }
170
+ }
171
+ // ============================================================================
172
+ // Value Conversion (Snapshot → Live)
173
+ // ============================================================================
174
+ /**
175
+ * Convert a snapshot cell value to a `FormulaResult` suitable for `cell.result`.
176
+ *
177
+ * `null` represents a BLANK — the formula produced no value (e.g.
178
+ * `=IF(FALSE, 1, )` or an empty reference). Returning literal `0` for
179
+ * that case conflates "formula returned 0" with "formula returned
180
+ * nothing", which breaks downstream consumers that distinguish the two
181
+ * (for instance, `ISBLANK(A1)` on a cell that holds `=B1` where B1 is
182
+ * empty should stay TRUE, not flip to FALSE because we injected 0).
183
+ */
184
+ function snapshotValueToResult(val) {
185
+ if (val === null) {
186
+ return undefined;
187
+ }
188
+ if (typeof val === "number" || typeof val === "string" || typeof val === "boolean") {
189
+ return val;
190
+ }
191
+ if (isSnapshotError(val)) {
192
+ return val;
193
+ }
194
+ return undefined;
195
+ }
196
+ /**
197
+ * Convert a snapshot cell value to a raw value suitable for `cell.value`.
198
+ */
199
+ function snapshotValueToRaw(val) {
200
+ if (val === null) {
201
+ return null;
202
+ }
203
+ if (typeof val === "number" || typeof val === "string" || typeof val === "boolean") {
204
+ return val;
205
+ }
206
+ if (isSnapshotError(val)) {
207
+ return val;
208
+ }
209
+ return null;
210
+ }
211
+ function isSnapshotError(val) {
212
+ return val !== null && typeof val === "object" && "error" in val;
213
+ }