@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
package/README.md CHANGED
@@ -12,13 +12,13 @@ ExcelTS is a zero-dependency TypeScript toolkit for spreadsheets and documents:
12
12
 
13
13
  - **AI-Friendly** — Clean, consistent API designed for AI coding agents. Every module has comprehensive documentation and runnable examples for AI to learn from
14
14
  - **Zero Runtime Dependencies** — Pure TypeScript, no external packages
15
- - **Seven Modules** — Excel, PDF, CSV, Markdown, XML, Archive, Stream
15
+ - **Eight Modules** — Excel, Formula, PDF, CSV, Markdown, XML, Archive, Stream
16
16
  - **Cross-Platform** — Node.js 22+, Bun, Chrome 89+, Firefox 102+, Safari 14.1+
17
17
  - **ESM First** — Native ES Modules with CommonJS compatibility and full tree-shaking
18
18
 
19
19
  ## Modules
20
20
 
21
- ExcelTS is organized into seven standalone modules. Each module has its own documentation and runnable examples.
21
+ ExcelTS is organized into eight standalone modules. Each module has its own documentation and runnable examples.
22
22
 
23
23
  ### Excel — XLSX/JSON Workbook Manager
24
24
 
@@ -27,6 +27,13 @@ Create, read, and modify Excel spreadsheets with full styling, formulas, images,
27
27
  - [Documentation](src/modules/excel/README.md) | [中文](src/modules/excel/README_zh.md)
28
28
  - [Examples](src/modules/excel/examples/)
29
29
 
30
+ ### Formula — Excel-Compatible Calculation Engine
31
+
32
+ Standalone 433-function calculation engine with tokenizer, parser, dependency graph, dynamic-array spill, and `LAMBDA`/`LET`/`MAP`/`REDUCE` support. Ships as a separate subpath so it stays out of bundles that only need to read/write XLSX. **Works in two modes**: paired with `Workbook` via `installFormulaEngine()`, or standalone on any `WorkbookLike` host via `calculateFormulas()` — the engine itself has zero excel runtime dependencies.
33
+
34
+ - [Documentation](src/modules/formula/README.md) | [中文](src/modules/formula/README_zh.md)
35
+ - [Examples](src/modules/formula/examples/)
36
+
30
37
  ### PDF — Zero-Dependency PDF Engine
31
38
 
32
39
  Full-featured PDF generation, reading, building, editing, and signing. Write PDFs with font embedding, AES-256 encryption, images, and Excel-to-PDF conversion. Build free-form PDFs with text, vector graphics, SVG paths, annotations, and form fields. Edit existing PDFs with overlays, form filling, page manipulation, and merging. Read any PDF with text, image, annotation, form field, bookmark, and metadata extraction. Verify and create digital signatures with PKCS#7/CMS.
@@ -142,6 +149,18 @@ const archive = await zip().add("hello.txt", "Hello!").bytes();
142
149
  // Markdown — parse and format tables
143
150
  import { parseMarkdown, formatMarkdown } from "@cj-tech-master/excelts/markdown";
144
151
  const table = parseMarkdown("| A | B |\n|---|---|\n| 1 | 2 |");
152
+
153
+ // Formula — opt-in calculation engine (kept out of the base bundle)
154
+ //
155
+ // Mode A: paired with Workbook — enables wb.calculateFormulas()
156
+ import { installFormulaEngine } from "@cj-tech-master/excelts/formula";
157
+ installFormulaEngine(); // once at startup
158
+ sheet.getCell("A4").value = { formula: "SUM(A1:A3)" };
159
+ workbook.calculateFormulas(); // now populates cell.result
160
+
161
+ // Mode B: standalone — pure function, zero excel runtime, any WorkbookLike
162
+ import { calculateFormulas } from "@cj-tech-master/excelts/formula";
163
+ calculateFormulas(anyWorkbookLikeObject);
145
164
  ```
146
165
 
147
166
  ## Browser Support
@@ -159,6 +178,10 @@ const buffer = await new Workbook().addWorksheet("S1").workbook.xlsx.writeBuffer
159
178
  <script src="https://unpkg.com/@cj-tech-master/excelts/dist/iife/excelts.iife.min.js"></script>
160
179
  ```
161
180
 
181
+ > The IIFE bundle does not include the formula calculation engine. Use
182
+ > ESM + `@cj-tech-master/excelts/formula` if you need
183
+ > `Workbook.calculateFormulas()`.
184
+
162
185
  For older browsers without native `CompressionStream` API, ExcelTS automatically uses a built-in pure JavaScript DEFLATE implementation — no polyfills needed.
163
186
 
164
187
  ## Requirements
package/README_zh.md CHANGED
@@ -10,23 +10,30 @@ ExcelTS 正是为了解决这个问题而生。一个包、一套 API、一份
10
10
 
11
11
  ExcelTS 是一个零依赖的 TypeScript 电子表格和文档工具包:
12
12
 
13
- - **AI 友好** — 简洁一致的 API,专为 AI 编程助手设计。每个模块都配有完整的文档和可运行的示例供 AI 学习
14
- - **零运行时依赖** — 纯 TypeScript,无外部包
15
- - **七大模块** — Excel、PDF、CSV、Markdown、XML、Archive、Stream
13
+ - **AI 友好** — 简洁一致的 API,专为 AI 编程助手设计。每个模块都配有完整的文档和可运行的示例供 AI 学习
14
+ - **零运行时依赖** — 纯 TypeScript,无外部包
15
+ - **八大模块** — Excel、Formula、PDF、CSV、Markdown、XML、Archive、Stream
16
16
  - **跨平台** — Node.js 22+、Bun、Chrome 89+、Firefox 102+、Safari 14.1+
17
- - **ESM 优先** — 原生 ES Modules,兼容 CommonJS,完整的 tree-shaking 支持
17
+ - **ESM 优先** — 原生 ES Modules,兼容 CommonJS,完整的 tree-shaking 支持
18
18
 
19
19
  ## 模块
20
20
 
21
- ExcelTS 由七个独立模块组成,每个模块都有自己的文档和可运行示例。
21
+ ExcelTS 由八个独立模块组成,每个模块都有自己的文档和可运行示例。
22
22
 
23
23
  ### Excel — XLSX/JSON 工作簿管理器
24
24
 
25
- 创建、读取和修改 Excel 电子表格,完整支持样式、公式、图片和流式处理。
25
+ 创建、读取和修改 Excel 电子表格,完整支持样式、公式、图片和流式处理。
26
26
 
27
27
  - [文档](src/modules/excel/README.md) | [中文](src/modules/excel/README_zh.md)
28
28
  - [示例](src/modules/excel/examples/)
29
29
 
30
+ ### Formula — Excel 兼容公式引擎
31
+
32
+ 独立的 433 函数计算引擎,包含 tokenizer、parser、依赖图、动态数组 spill,支持 `LAMBDA`/`LET`/`MAP`/`REDUCE`。作为单独的 subpath 发布,不会被打进只读写 XLSX 的 bundle。**两种使用模式**:通过 `installFormulaEngine()` 和 `Workbook` 配合使用,或通过 `calculateFormulas()` 对任意 `WorkbookLike` 宿主单独使用 — 引擎本身**零 excel 运行时依赖**。
33
+
34
+ - [文档](src/modules/formula/README.md) | [中文](src/modules/formula/README_zh.md)
35
+ - [示例](src/modules/formula/examples/)
36
+
30
37
  ### PDF — 零依赖 PDF 引擎
31
38
 
32
39
  功能完整的 PDF 生成和读取。写入支持字体嵌入、AES-256 加密、图片和 Excel 转 PDF。读取支持从任意 PDF 提取文本、图片、注解、表单字段和元数据。
@@ -127,6 +134,18 @@ const archive = await zip().add("hello.txt", "Hello!").bytes();
127
134
  // Markdown — 解析和格式化表格
128
135
  import { parseMarkdown, formatMarkdown } from "@cj-tech-master/excelts/markdown";
129
136
  const table = parseMarkdown("| A | B |\n|---|---|\n| 1 | 2 |");
137
+
138
+ // Formula — 可选的公式引擎(默认不打进主 bundle)
139
+ //
140
+ // 模式 A: 配合 Workbook — 启用 wb.calculateFormulas()
141
+ import { installFormulaEngine } from "@cj-tech-master/excelts/formula";
142
+ installFormulaEngine(); // 启动时调用一次
143
+ sheet.getCell("A4").value = { formula: "SUM(A1:A3)" };
144
+ workbook.calculateFormulas(); // 现在能填 cell.result 了
145
+
146
+ // 模式 B: 单独使用 — 纯函数,零 excel 运行时,接受任意 WorkbookLike
147
+ import { calculateFormulas } from "@cj-tech-master/excelts/formula";
148
+ calculateFormulas(anyWorkbookLikeObject);
130
149
  ```
131
150
 
132
151
  ## 浏览器支持
@@ -144,6 +163,10 @@ const buffer = await new Workbook().addWorksheet("S1").workbook.xlsx.writeBuffer
144
163
  <script src="https://unpkg.com/@cj-tech-master/excelts/dist/iife/excelts.iife.min.js"></script>
145
164
  ```
146
165
 
166
+ > IIFE 打包产物不包含公式计算引擎。如果需要调用
167
+ > `Workbook.calculateFormulas()`,请改用 ESM + 导入
168
+ > `@cj-tech-master/excelts/formula`。
169
+
147
170
  对于不支持原生 `CompressionStream` API 的旧版浏览器,ExcelTS 自动使用内置的纯 JavaScript DEFLATE 实现 — 无需 polyfill。
148
171
 
149
172
  ## 系统要求
@@ -31,7 +31,7 @@ export { DefinedNames, type DefinedNameModel } from "./modules/excel/defined-nam
31
31
  export type { CheckboxState } from "./modules/excel/form-control.js";
32
32
  export type { ColumnDefn, ColumnHeaderValue } from "./modules/excel/column.js";
33
33
  export type { RangeInput } from "./modules/excel/range.js";
34
- export type { WorkbookModel, WorkbookMedia } from "./modules/excel/workbook.js";
34
+ export type { WorkbookModel, WorkbookMedia, WorkbookProtectionModel, ExternalLinkModel, ExternalLinkCachedSheet } from "./modules/excel/workbook.js";
35
35
  export { decodeCol, encodeCol, decodeRow, encodeRow, decodeCell, encodeCell, decodeRange, encodeRange } from "./modules/excel/utils/address.js";
36
36
  export type { CellAddress, SheetRange, Origin } from "./modules/excel/utils/address.js";
37
37
  export type { SheetToJSONOptions, AddJSONOptions, AddAOAOptions } from "./modules/excel/worksheet.js";
@@ -16,6 +16,10 @@ export * from "./modules/excel/anchor.js";
16
16
  export { Table } from "./modules/excel/table.js";
17
17
  export { DataValidations } from "./modules/excel/data-validations.js";
18
18
  export { FormCheckbox } from "./modules/excel/form-control.js";
19
+ // Note: the formula engine lives at the `./formula` subpath so it stays
20
+ // out of bundles that only need to read / write XLSX files. Import
21
+ // `@cj-tech-master/excelts/formula` to enable `Workbook.calculateFormulas()`
22
+ // and automatic recalculation in `excelToPdf()`.
19
23
  // =============================================================================
20
24
  // Enums
21
25
  // =============================================================================
@@ -30,7 +30,7 @@ export { DefinedNames, type DefinedNameModel } from "./modules/excel/defined-nam
30
30
  export type { CheckboxState } from "./modules/excel/form-control.js";
31
31
  export type { ColumnDefn, ColumnHeaderValue } from "./modules/excel/column.js";
32
32
  export type { RangeInput } from "./modules/excel/range.js";
33
- export type { WorkbookModel, WorkbookMedia } from "./modules/excel/workbook.js";
33
+ export type { WorkbookModel, WorkbookMedia, WorkbookProtectionModel, ExternalLinkModel, ExternalLinkCachedSheet } from "./modules/excel/workbook.js";
34
34
  export type { NodeInput } from "./modules/excel/stream/workbook-reader.js";
35
35
  export { decodeCol, encodeCol, decodeRow, encodeRow, decodeCell, encodeCell, decodeRange, encodeRange } from "./modules/excel/utils/address.js";
36
36
  export type { CellAddress, SheetRange, Origin } from "./modules/excel/utils/address.js";
@@ -12,6 +12,10 @@ export * from "./modules/excel/anchor.js";
12
12
  export { Table } from "./modules/excel/table.js";
13
13
  export { DataValidations } from "./modules/excel/data-validations.js";
14
14
  export { FormCheckbox } from "./modules/excel/form-control.js";
15
+ // Note: the formula engine lives at the `./formula` subpath so it stays
16
+ // out of bundles that only need to read / write XLSX files. Import
17
+ // `@cj-tech-master/excelts/formula` to enable `Workbook.calculateFormulas()`
18
+ // and automatic recalculation in `excelToPdf()`.
15
19
  // =============================================================================
16
20
  // Node.js Only: Streaming Classes
17
21
  // These can also be accessed via Workbook.createStreamWriter/createStreamReader
@@ -2,7 +2,7 @@ import type { Column } from "./column.js";
2
2
  import type { ValueType, FormulaType } from "./enums.js";
3
3
  import { Note } from "./note.js";
4
4
  import type { Row } from "./row.js";
5
- import type { Style, NumFmt, Font, Alignment, Protection, Borders, Fill, CellRichTextValue, CellErrorValue, DataValidation, CellValue, CellHyperlinkValue } from "./types.js";
5
+ import type { Style, NumFmt, Font, Alignment, Protection, Borders, Fill, CellRichTextValue, CellErrorValue, DataValidation, CellValue, CellValueInput, CellHyperlinkValue, RichText } from "./types.js";
6
6
  import type { Workbook } from "./workbook.js";
7
7
  import type { Worksheet } from "./worksheet.js";
8
8
  export type FormulaResult = string | number | boolean | Date | CellErrorValue;
@@ -13,6 +13,7 @@ export interface FormulaValueData {
13
13
  sharedFormula?: string;
14
14
  result?: FormulaResult;
15
15
  date1904?: boolean;
16
+ isDynamicArray?: boolean;
16
17
  }
17
18
  interface FullAddress {
18
19
  sheetName: string;
@@ -62,12 +63,24 @@ export interface CellModel {
62
63
  formula?: string;
63
64
  sharedFormula?: string;
64
65
  result?: FormulaResult;
65
- richText?: CellRichTextValue;
66
+ /**
67
+ * Rich-text runs associated with this cell.
68
+ *
69
+ * - When `type === RichText`, this holds a CellRichTextValue (object wrapping
70
+ * the runs array) — this is the historical, cell-level rich-text payload.
71
+ * - When `type === Hyperlink`, this holds a plain RichText[] — the runs used
72
+ * for formatted display of the hyperlink text.
73
+ *
74
+ * Callers should branch on `type` before accessing the shape.
75
+ */
76
+ richText?: CellRichTextValue | RichText[];
66
77
  sharedString?: number;
67
78
  error?: CellErrorValue;
68
79
  rawValue?: unknown;
80
+ isDynamicArray?: boolean;
69
81
  }
70
82
  export type CellValueType = CellValue;
83
+ export type CellValueInputType = CellValueInput;
71
84
  declare class Cell {
72
85
  static Types: typeof ValueType;
73
86
  private _row;
@@ -111,7 +124,7 @@ declare class Cell {
111
124
  get isHyperlink(): boolean;
112
125
  get hyperlink(): string | undefined;
113
126
  get value(): CellValueType;
114
- set value(v: CellValueType);
127
+ set value(v: CellValueInputType);
115
128
  get note(): string | NoteConfig | undefined;
116
129
  set note(note: string | NoteConfig);
117
130
  get comment(): Note | undefined;
@@ -121,6 +134,7 @@ declare class Cell {
121
134
  toString(): string;
122
135
  get formula(): string | undefined;
123
136
  get result(): FormulaResult | undefined;
137
+ set result(value: FormulaResult | undefined);
124
138
  get formulaType(): FormulaType;
125
139
  get fullAddress(): FullAddress;
126
140
  get name(): string;
@@ -10,6 +10,51 @@ import { escapeHtml } from "./utils/under-dash.js";
10
10
  // empty string, and empty objects `{}`. This is used to prevent an empty `{}`
11
11
  // style property on a row from shadowing a real style property on a column.
12
12
  const hasOwnKeys = (v) => !!v && (typeof v !== "object" || Object.keys(v).length > 0);
13
+ /**
14
+ * Flatten a rich-text array into its plain-text representation by
15
+ * concatenating each run's `text`. Missing/null runs contribute "".
16
+ */
17
+ function flattenRichText(runs) {
18
+ let out = "";
19
+ for (const run of runs) {
20
+ if (run && typeof run.text === "string") {
21
+ out += run.text;
22
+ }
23
+ }
24
+ return out;
25
+ }
26
+ /**
27
+ * Normalize a CellHyperlinkValue so the {@link NormalizedHyperlink} invariants
28
+ * hold.
29
+ *
30
+ * - If the caller supplied `richText` but no `text`, text is derived.
31
+ * - If the caller supplied `text` but no `richText`, richText stays absent.
32
+ * - If both are supplied, `richText` wins and `text` is regenerated
33
+ * (to keep `text === flatten(richText)`).
34
+ * - An empty `richText: []` is dropped (treated as "no rich text").
35
+ */
36
+ function normalizeHyperlinkValue(value) {
37
+ let text;
38
+ let richText;
39
+ if (Array.isArray(value.richText) && value.richText.length > 0) {
40
+ richText = value.richText;
41
+ text = flattenRichText(richText);
42
+ }
43
+ else {
44
+ text = typeof value.text === "string" ? value.text : "";
45
+ }
46
+ const out = {
47
+ text,
48
+ hyperlink: typeof value.hyperlink === "string" ? value.hyperlink : ""
49
+ };
50
+ if (richText) {
51
+ out.richText = richText;
52
+ }
53
+ if (typeof value.tooltip === "string" && value.tooltip.length > 0) {
54
+ out.tooltip = value.tooltip;
55
+ }
56
+ return out;
57
+ }
13
58
  // Cell requirements
14
59
  // Operate inside a worksheet
15
60
  // Store and retrieve a value with a range of types: text, number, date, hyperlink, reference, formula, etc.
@@ -234,12 +279,30 @@ class Cell {
234
279
  }
235
280
  /** @internal */
236
281
  _upgradeToHyperlink(hyperlink) {
237
- // if this cell is a string, turn it into a Hyperlink
238
- if (this.type === Cell.Types.String) {
239
- this._value = Value.create(Cell.Types.Hyperlink, this, {
240
- text: String(this._value.value),
241
- hyperlink
242
- });
282
+ // Upgrade this cell to a Hyperlink while preserving the existing display
283
+ // text. Supports promotion from both plain String cells and RichText cells.
284
+ // For RichText cells, the runs are preserved on the new hyperlink value.
285
+ switch (this.type) {
286
+ case Cell.Types.String: {
287
+ this._value = Value.create(Cell.Types.Hyperlink, this, {
288
+ text: String(this._value.value),
289
+ hyperlink
290
+ });
291
+ break;
292
+ }
293
+ case Cell.Types.RichText: {
294
+ const current = this._value.value;
295
+ const runs = current && Array.isArray(current.richText) ? current.richText : [];
296
+ this._value = Value.create(Cell.Types.Hyperlink, this, {
297
+ text: flattenRichText(runs),
298
+ richText: runs.length > 0 ? runs : undefined,
299
+ hyperlink
300
+ });
301
+ break;
302
+ }
303
+ default:
304
+ // Other cell types (Number, Date, Formula, ...) are not auto-upgraded.
305
+ break;
243
306
  }
244
307
  }
245
308
  // =========================================================================
@@ -250,6 +313,11 @@ class Cell {
250
313
  get result() {
251
314
  return this._value.result;
252
315
  }
316
+ set result(value) {
317
+ if (this.type === Cell.Types.Formula) {
318
+ this._value.result = value;
319
+ }
320
+ }
253
321
  get formulaType() {
254
322
  return this._value.formulaType ?? Enums.FormulaType.None;
255
323
  }
@@ -506,34 +574,95 @@ class HyperlinkValue {
506
574
  constructor(cell, value) {
507
575
  this.model = {
508
576
  address: cell.address,
509
- type: Cell.Types.Hyperlink,
510
- text: value ? value.text : undefined,
511
- hyperlink: value ? value.hyperlink : undefined
577
+ type: Cell.Types.Hyperlink
512
578
  };
513
- if (value && value.tooltip) {
514
- this.model.tooltip = value.tooltip;
579
+ if (value) {
580
+ // Formula + hyperlink: surface as a Hyperlink whose display is the
581
+ // formula's evaluated result, but persist the formula on the model so
582
+ // it round-trips on write. The cell value getter ignores the formula
583
+ // fields, keeping the public Hyperlink shape clean.
584
+ if ("formula" in value && typeof value.formula === "string") {
585
+ const fh = value;
586
+ const display = fh.result === undefined || fh.result === null ? "" : String(fh.result);
587
+ this.model.text = display;
588
+ this.model.hyperlink = fh.hyperlink ?? "";
589
+ if (fh.tooltip !== undefined) {
590
+ this.model.tooltip = fh.tooltip;
591
+ }
592
+ // Internal-only fields preserved for write-time re-emission.
593
+ this.model.formula =
594
+ fh.formula;
595
+ if (fh.result !== undefined) {
596
+ this.model.result = fh.result;
597
+ }
598
+ return;
599
+ }
600
+ const normalized = normalizeHyperlinkValue(value);
601
+ this.model.text = normalized.text;
602
+ this.model.hyperlink = normalized.hyperlink;
603
+ if (normalized.richText) {
604
+ this.model.richText = normalized.richText;
605
+ }
606
+ if (normalized.tooltip !== undefined) {
607
+ this.model.tooltip = normalized.tooltip;
608
+ }
515
609
  }
516
610
  }
517
611
  get value() {
518
- return {
612
+ const out = {
519
613
  text: this.model.text ?? "",
520
- hyperlink: this.model.hyperlink ?? "",
521
- tooltip: this.model.tooltip
614
+ hyperlink: this.model.hyperlink ?? ""
522
615
  };
616
+ if (this.model.richText && this.model.richText.length > 0) {
617
+ out.richText = this.model.richText;
618
+ }
619
+ if (this.model.tooltip !== undefined) {
620
+ out.tooltip = this.model.tooltip;
621
+ }
622
+ return out;
523
623
  }
524
624
  set value(value) {
525
- this.model.text = value.text;
526
- this.model.hyperlink = value.hyperlink;
527
- if (value.tooltip) {
528
- this.model.tooltip = value.tooltip;
625
+ const normalized = normalizeHyperlinkValue(value);
626
+ this.model.text = normalized.text;
627
+ this.model.hyperlink = normalized.hyperlink;
628
+ if (normalized.richText) {
629
+ this.model.richText = normalized.richText;
630
+ }
631
+ else {
632
+ delete this.model.richText;
633
+ }
634
+ if (normalized.tooltip !== undefined) {
635
+ this.model.tooltip = normalized.tooltip;
636
+ }
637
+ else {
638
+ delete this.model.tooltip;
529
639
  }
530
640
  }
531
641
  get text() {
532
642
  return this.model.text;
533
643
  }
534
644
  set text(value) {
645
+ // Setting text while richText is present would break the invariant
646
+ // (text must equal flattenRichText(richText)). Dropping richText is the
647
+ // only safe resolution.
648
+ if (this.model.richText) {
649
+ delete this.model.richText;
650
+ }
535
651
  this.model.text = value;
536
652
  }
653
+ get richText() {
654
+ return this.model.richText;
655
+ }
656
+ set richText(value) {
657
+ if (Array.isArray(value) && value.length > 0) {
658
+ this.model.richText = value;
659
+ this.model.text = flattenRichText(value);
660
+ }
661
+ else {
662
+ delete this.model.richText;
663
+ // leave model.text untouched — caller may still want the plain text
664
+ }
665
+ }
537
666
  get hyperlink() {
538
667
  return this.model.hyperlink;
539
668
  }
@@ -625,7 +754,8 @@ class FormulaValue {
625
754
  ref: value ? value.ref : undefined,
626
755
  formula: value ? value.formula : undefined,
627
756
  sharedFormula: value ? value.sharedFormula : undefined,
628
- result: value ? value.result : undefined
757
+ result: value ? value.result : undefined,
758
+ isDynamicArray: value ? value.isDynamicArray : undefined
629
759
  };
630
760
  }
631
761
  _copyModel(model) {
@@ -645,6 +775,9 @@ class FormulaValue {
645
775
  if (model.sharedFormula) {
646
776
  copy.sharedFormula = model.sharedFormula;
647
777
  }
778
+ if (model.isDynamicArray) {
779
+ copy.isDynamicArray = model.isDynamicArray;
780
+ }
648
781
  return copy;
649
782
  }
650
783
  get value() {
@@ -666,6 +799,9 @@ class FormulaValue {
666
799
  if (value.sharedFormula) {
667
800
  this.model.sharedFormula = value.sharedFormula;
668
801
  }
802
+ if (value.isDynamicArray !== undefined) {
803
+ this.model.isDynamicArray = value.isDynamicArray;
804
+ }
669
805
  }
670
806
  validate(value) {
671
807
  switch (Value.getType(value)) {
@@ -953,14 +1089,26 @@ const Value = {
953
1089
  if ("checkbox" in value && typeof value.checkbox === "boolean") {
954
1090
  return Cell.Types.Checkbox;
955
1091
  }
956
- if ("text" in value && value.text && "hyperlink" in value && value.hyperlink) {
957
- return Cell.Types.Hyperlink;
1092
+ // Hyperlink detection: requires `hyperlink` and either non-empty `text`
1093
+ // or a non-empty `richText` array, OR a formula (formula+hyperlink is
1094
+ // surfaced as a Hyperlink with the formula's result as display).
1095
+ // Checked before RichText/Formula so combined payloads route correctly.
1096
+ if ("hyperlink" in value && typeof value.hyperlink === "string" && value.hyperlink) {
1097
+ const hasText = "text" in value && typeof value.text === "string" && value.text.length > 0;
1098
+ const hasRichText = "richText" in value && Array.isArray(value.richText) && value.richText.length > 0;
1099
+ const hasFormula = "formula" in value && typeof value.formula === "string";
1100
+ if (hasText || hasRichText || hasFormula) {
1101
+ return Cell.Types.Hyperlink;
1102
+ }
958
1103
  }
959
1104
  if (("formula" in value && value.formula) ||
960
1105
  ("sharedFormula" in value && value.sharedFormula)) {
961
1106
  return Cell.Types.Formula;
962
1107
  }
963
- if ("richText" in value && value.richText) {
1108
+ // RichText only when the runs array is non-empty. An empty `richText: []`
1109
+ // carries no content and falls through to JSON rather than producing a
1110
+ // RichText cell with no runs.
1111
+ if ("richText" in value && Array.isArray(value.richText) && value.richText.length > 0) {
964
1112
  return Cell.Types.RichText;
965
1113
  }
966
1114
  if ("sharedString" in value && value.sharedString) {
@@ -2,6 +2,7 @@ import { Range } from "./range.js";
2
2
  import type { Address } from "./types.js";
3
3
  import { CellMatrix } from "./utils/cell-matrix.js";
4
4
  import { type DecodedRange } from "./utils/col-cache.js";
5
+ import { type SyntaxProbe } from "../formula/default-syntax-probe.js";
5
6
  interface DefinedNameCell {
6
7
  sheetName?: string;
7
8
  address: string;
@@ -13,25 +14,119 @@ type CellLocation = Address | DecodedRange;
13
14
  interface DefinedNameModel {
14
15
  name: string;
15
16
  ranges: string[];
17
+ localSheetId?: number;
18
+ /** Formula expression for formula-based defined names (e.g. "LAMBDA(x,y,x+y)") */
19
+ formulaExpression?: string;
20
+ /** Original XML text — preserved for opaque names round-trip */
21
+ rawText?: string;
22
+ /**
23
+ * Classification determined by the semantic layer:
24
+ * - "reference": pure cell/range union — stored in matrixMap
25
+ * - "formula": parseable expression — stored in formulaMap
26
+ * - "opaque": unrecognised content preserved for round-trip — stored in opaqueMap
27
+ */
28
+ kind?: "reference" | "formula" | "opaque";
29
+ }
30
+ /** Stored entry for an opaque (unrecognised) defined name. */
31
+ interface OpaqueEntry {
32
+ rawText: string;
33
+ localSheetId?: number;
16
34
  }
17
35
  declare class DefinedNames {
18
36
  matrixMap: Record<string, CellMatrix>;
19
- constructor();
37
+ /**
38
+ * Formula-based defined names: storageKey → formula expression string.
39
+ */
40
+ formulaMap: Record<string, string>;
41
+ /**
42
+ * Tracks the localSheetId for each storage key.
43
+ * If a key is not in this map, the name is workbook-scoped (global).
44
+ */
45
+ localSheetIdMap: Record<string, number>;
46
+ /**
47
+ * Opaque defined names: storageKey → original text + optional localSheetId.
48
+ */
49
+ opaqueMap: Record<string, OpaqueEntry>;
50
+ /**
51
+ * Reverse mapping: storageKey → original name (bare, without scope suffix).
52
+ * Needed because storageKey encodes the scope, but consumers need the bare name.
53
+ */
54
+ nameForKey: Record<string, string>;
55
+ /**
56
+ * Optional explicit formula-syntax probe. When set, this is used to
57
+ * classify non-range, non-wrapper defined-name text during `set model`.
58
+ * When unset, the classifier falls back to the process-wide default
59
+ * probe (set by `installFormulaEngine()`). When neither is available,
60
+ * classification is conservative — non-range text becomes opaque.
61
+ */
62
+ private readonly _explicitProbe;
63
+ /**
64
+ * @param probe Optional formula-syntax probe used when classifying
65
+ * defined-name text. Injecting a probe here makes classification
66
+ * deterministic for this instance regardless of process-global
67
+ * `installFormulaEngine()` state. When omitted, the instance defers
68
+ * to the default probe at classification time (see `set model`).
69
+ */
70
+ constructor(probe?: SyntaxProbe);
20
71
  getMatrix(name: string): CellMatrix;
21
72
  add(locStr: string, name: string): void;
22
73
  addEx(location: CellLocation, name: string): void;
74
+ /**
75
+ * Register a formula-based defined name.
76
+ *
77
+ * Unlike `add()` which binds a name to a cell/range reference, this binds
78
+ * a name to an arbitrary formula expression that will be evaluated at
79
+ * calculation time.
80
+ *
81
+ * @param name - The defined name (e.g. "MyArray")
82
+ * @param expression - The formula expression (e.g. "{1,2;3,4}", "LAMBDA(x,y,x+y)")
83
+ */
84
+ addFormula(name: string, expression: string): void;
23
85
  remove(locStr: string, name: string): void;
24
86
  removeEx(location: CellLocation, name: string): void;
25
87
  removeAllNames(location: CellLocation): void;
26
88
  forEach(callback: (name: string, cell: DefinedNameCell) => void): void;
27
89
  getNames(addressStr: string): string[];
28
90
  getNamesEx(address: Address): string[];
91
+ /**
92
+ * Return all defined name entries in this collection, including scope info.
93
+ * Each entry has the bare name and optional localSheetId.
94
+ * Same bare name may appear multiple times with different scopes.
95
+ */
96
+ getAllNames(): {
97
+ name: string;
98
+ localSheetId?: number;
99
+ }[];
100
+ /**
101
+ * Return all defined name entries with full details (name, ranges, scope).
102
+ *
103
+ * This is the primary enumeration API. Each entry is self-contained —
104
+ * no second lookup is needed. Same bare name may appear multiple times
105
+ * with different scopes.
106
+ */
107
+ getAllEntries(): DefinedNameModel[];
29
108
  _explore(matrix: CellMatrix, cell: DefinedNameCell): Range;
109
+ /**
110
+ * Get ranges for a specific scoped entry.
111
+ *
112
+ * Unlike `getRanges(name)` which uses the bare name (and may hit the
113
+ * wrong scope when the same name exists both globally and locally),
114
+ * this method uses the internal `storageKey` to look up the exact entry.
115
+ */
116
+ getRangesScoped(name: string, localSheetId?: number): DefinedNameModel;
30
117
  getRanges(name: string, matrix?: CellMatrix): DefinedNameModel;
31
118
  normaliseMatrix(matrix: CellMatrix, sheetName: string): void;
32
119
  spliceRows(sheetName: string, start: number, numDelete: number, numInsert: number): void;
33
120
  spliceColumns(sheetName: string, start: number, numDelete: number, numInsert: number): void;
34
121
  get model(): DefinedNameModel[];
122
+ /**
123
+ * Deserialise an array of `DefinedNameModel` entries (typically from XLSX parsing).
124
+ *
125
+ * Stage 2 of the two-phase design: each entry's `rawText` is classified
126
+ * into reference / formula / opaque by `classifyDefinedName()`. Entries
127
+ * that arrive without `rawText` (programmatic API) fall back to inspecting
128
+ * the existing `ranges` and `formulaExpression` fields for compatibility.
129
+ */
35
130
  set model(value: DefinedNameModel[]);
36
131
  }
37
132
  export { DefinedNames, type DefinedNameModel };