hanseol-dev 4.0.12

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 (720) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +267 -0
  3. package/dist/agents/base/base-agent.d.ts +38 -0
  4. package/dist/agents/base/base-agent.d.ts.map +1 -0
  5. package/dist/agents/base/base-agent.js +69 -0
  6. package/dist/agents/base/base-agent.js.map +1 -0
  7. package/dist/agents/docs-search/index.d.ts +33 -0
  8. package/dist/agents/docs-search/index.d.ts.map +1 -0
  9. package/dist/agents/docs-search/index.js +244 -0
  10. package/dist/agents/docs-search/index.js.map +1 -0
  11. package/dist/agents/index.d.ts +4 -0
  12. package/dist/agents/index.d.ts.map +1 -0
  13. package/dist/agents/index.js +4 -0
  14. package/dist/agents/index.js.map +1 -0
  15. package/dist/agents/planner/index.d.ts +19 -0
  16. package/dist/agents/planner/index.d.ts.map +1 -0
  17. package/dist/agents/planner/index.js +339 -0
  18. package/dist/agents/planner/index.js.map +1 -0
  19. package/dist/cli.d.ts +3 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +205 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/constants.d.ts +10 -0
  24. package/dist/constants.d.ts.map +1 -0
  25. package/dist/constants.js +12 -0
  26. package/dist/constants.js.map +1 -0
  27. package/dist/core/auth/oauth-login.d.ts +19 -0
  28. package/dist/core/auth/oauth-login.d.ts.map +1 -0
  29. package/dist/core/auth/oauth-login.js +197 -0
  30. package/dist/core/auth/oauth-login.js.map +1 -0
  31. package/dist/core/compact/compact-manager.d.ts +22 -0
  32. package/dist/core/compact/compact-manager.d.ts.map +1 -0
  33. package/dist/core/compact/compact-manager.js +75 -0
  34. package/dist/core/compact/compact-manager.js.map +1 -0
  35. package/dist/core/compact/compact-prompts.d.ts +11 -0
  36. package/dist/core/compact/compact-prompts.d.ts.map +1 -0
  37. package/dist/core/compact/compact-prompts.js +90 -0
  38. package/dist/core/compact/compact-prompts.js.map +1 -0
  39. package/dist/core/compact/context-tracker.d.ts +28 -0
  40. package/dist/core/compact/context-tracker.d.ts.map +1 -0
  41. package/dist/core/compact/context-tracker.js +71 -0
  42. package/dist/core/compact/context-tracker.js.map +1 -0
  43. package/dist/core/compact/index.d.ts +4 -0
  44. package/dist/core/compact/index.d.ts.map +1 -0
  45. package/dist/core/compact/index.js +4 -0
  46. package/dist/core/compact/index.js.map +1 -0
  47. package/dist/core/config/config-manager.d.ts +43 -0
  48. package/dist/core/config/config-manager.d.ts.map +1 -0
  49. package/dist/core/config/config-manager.js +254 -0
  50. package/dist/core/config/config-manager.js.map +1 -0
  51. package/dist/core/config/index.d.ts +2 -0
  52. package/dist/core/config/index.d.ts.map +1 -0
  53. package/dist/core/config/index.js +2 -0
  54. package/dist/core/config/index.js.map +1 -0
  55. package/dist/core/docs-manager.d.ts +46 -0
  56. package/dist/core/docs-manager.d.ts.map +1 -0
  57. package/dist/core/docs-manager.js +475 -0
  58. package/dist/core/docs-manager.js.map +1 -0
  59. package/dist/core/llm/index.d.ts +2 -0
  60. package/dist/core/llm/index.d.ts.map +1 -0
  61. package/dist/core/llm/index.js +2 -0
  62. package/dist/core/llm/index.js.map +1 -0
  63. package/dist/core/llm/llm-client.d.ts +98 -0
  64. package/dist/core/llm/llm-client.d.ts.map +1 -0
  65. package/dist/core/llm/llm-client.js +1024 -0
  66. package/dist/core/llm/llm-client.js.map +1 -0
  67. package/dist/core/s3-auto-updater.d.ts +44 -0
  68. package/dist/core/s3-auto-updater.d.ts.map +1 -0
  69. package/dist/core/s3-auto-updater.js +158 -0
  70. package/dist/core/s3-auto-updater.js.map +1 -0
  71. package/dist/core/session/index.d.ts +2 -0
  72. package/dist/core/session/index.d.ts.map +1 -0
  73. package/dist/core/session/index.js +2 -0
  74. package/dist/core/session/index.js.map +1 -0
  75. package/dist/core/session/session-manager.d.ts +71 -0
  76. package/dist/core/session/session-manager.d.ts.map +1 -0
  77. package/dist/core/session/session-manager.js +250 -0
  78. package/dist/core/session/session-manager.js.map +1 -0
  79. package/dist/core/slash-command-handler.d.ts +32 -0
  80. package/dist/core/slash-command-handler.d.ts.map +1 -0
  81. package/dist/core/slash-command-handler.js +455 -0
  82. package/dist/core/slash-command-handler.js.map +1 -0
  83. package/dist/core/usage-tracker.d.ts +74 -0
  84. package/dist/core/usage-tracker.d.ts.map +1 -0
  85. package/dist/core/usage-tracker.js +279 -0
  86. package/dist/core/usage-tracker.js.map +1 -0
  87. package/dist/errors/base.d.ts +22 -0
  88. package/dist/errors/base.d.ts.map +1 -0
  89. package/dist/errors/base.js +43 -0
  90. package/dist/errors/base.js.map +1 -0
  91. package/dist/errors/file.d.ts +31 -0
  92. package/dist/errors/file.d.ts.map +1 -0
  93. package/dist/errors/file.js +110 -0
  94. package/dist/errors/file.js.map +1 -0
  95. package/dist/errors/index.d.ts +12 -0
  96. package/dist/errors/index.d.ts.map +1 -0
  97. package/dist/errors/index.js +42 -0
  98. package/dist/errors/index.js.map +1 -0
  99. package/dist/errors/llm.d.ts +26 -0
  100. package/dist/errors/llm.d.ts.map +1 -0
  101. package/dist/errors/llm.js +86 -0
  102. package/dist/errors/llm.js.map +1 -0
  103. package/dist/errors/network.d.ts +19 -0
  104. package/dist/errors/network.d.ts.map +1 -0
  105. package/dist/errors/network.js +82 -0
  106. package/dist/errors/network.js.map +1 -0
  107. package/dist/errors/quota.d.ts +25 -0
  108. package/dist/errors/quota.d.ts.map +1 -0
  109. package/dist/errors/quota.js +10 -0
  110. package/dist/errors/quota.js.map +1 -0
  111. package/dist/errors/validation.d.ts +19 -0
  112. package/dist/errors/validation.d.ts.map +1 -0
  113. package/dist/errors/validation.js +62 -0
  114. package/dist/errors/validation.js.map +1 -0
  115. package/dist/eval/eval-runner.d.ts +24 -0
  116. package/dist/eval/eval-runner.d.ts.map +1 -0
  117. package/dist/eval/eval-runner.js +291 -0
  118. package/dist/eval/eval-runner.js.map +1 -0
  119. package/dist/eval/index.d.ts +3 -0
  120. package/dist/eval/index.d.ts.map +1 -0
  121. package/dist/eval/index.js +3 -0
  122. package/dist/eval/index.js.map +1 -0
  123. package/dist/eval/types.d.ts +77 -0
  124. package/dist/eval/types.d.ts.map +1 -0
  125. package/dist/eval/types.js +2 -0
  126. package/dist/eval/types.js.map +1 -0
  127. package/dist/index.d.ts +4 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +6 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/orchestration/index.d.ts +4 -0
  132. package/dist/orchestration/index.d.ts.map +1 -0
  133. package/dist/orchestration/index.js +3 -0
  134. package/dist/orchestration/index.js.map +1 -0
  135. package/dist/orchestration/plan-executor.d.ts +28 -0
  136. package/dist/orchestration/plan-executor.d.ts.map +1 -0
  137. package/dist/orchestration/plan-executor.js +376 -0
  138. package/dist/orchestration/plan-executor.js.map +1 -0
  139. package/dist/orchestration/types.d.ts +65 -0
  140. package/dist/orchestration/types.d.ts.map +1 -0
  141. package/dist/orchestration/types.js +2 -0
  142. package/dist/orchestration/types.js.map +1 -0
  143. package/dist/orchestration/utils.d.ts +13 -0
  144. package/dist/orchestration/utils.d.ts.map +1 -0
  145. package/dist/orchestration/utils.js +81 -0
  146. package/dist/orchestration/utils.js.map +1 -0
  147. package/dist/prompts/agents/docs-search-decision.d.ts +6 -0
  148. package/dist/prompts/agents/docs-search-decision.d.ts.map +1 -0
  149. package/dist/prompts/agents/docs-search-decision.js +46 -0
  150. package/dist/prompts/agents/docs-search-decision.js.map +1 -0
  151. package/dist/prompts/agents/docs-search.d.ts +4 -0
  152. package/dist/prompts/agents/docs-search.d.ts.map +1 -0
  153. package/dist/prompts/agents/docs-search.js +70 -0
  154. package/dist/prompts/agents/docs-search.js.map +1 -0
  155. package/dist/prompts/agents/planning.d.ts +4 -0
  156. package/dist/prompts/agents/planning.d.ts.map +1 -0
  157. package/dist/prompts/agents/planning.js +179 -0
  158. package/dist/prompts/agents/planning.js.map +1 -0
  159. package/dist/prompts/index.d.ts +10 -0
  160. package/dist/prompts/index.d.ts.map +1 -0
  161. package/dist/prompts/index.js +10 -0
  162. package/dist/prompts/index.js.map +1 -0
  163. package/dist/prompts/shared/codebase-rules.d.ts +4 -0
  164. package/dist/prompts/shared/codebase-rules.d.ts.map +1 -0
  165. package/dist/prompts/shared/codebase-rules.js +16 -0
  166. package/dist/prompts/shared/codebase-rules.js.map +1 -0
  167. package/dist/prompts/shared/git-rules.d.ts +2 -0
  168. package/dist/prompts/shared/git-rules.d.ts.map +1 -0
  169. package/dist/prompts/shared/git-rules.js +87 -0
  170. package/dist/prompts/shared/git-rules.js.map +1 -0
  171. package/dist/prompts/shared/language-rules.d.ts +4 -0
  172. package/dist/prompts/shared/language-rules.d.ts.map +1 -0
  173. package/dist/prompts/shared/language-rules.js +22 -0
  174. package/dist/prompts/shared/language-rules.js.map +1 -0
  175. package/dist/prompts/shared/tool-usage.d.ts +12 -0
  176. package/dist/prompts/shared/tool-usage.d.ts.map +1 -0
  177. package/dist/prompts/shared/tool-usage.js +51 -0
  178. package/dist/prompts/shared/tool-usage.js.map +1 -0
  179. package/dist/prompts/system/compact.d.ts +3 -0
  180. package/dist/prompts/system/compact.d.ts.map +1 -0
  181. package/dist/prompts/system/compact.js +73 -0
  182. package/dist/prompts/system/compact.js.map +1 -0
  183. package/dist/prompts/system/plan-execute.d.ts +3 -0
  184. package/dist/prompts/system/plan-execute.d.ts.map +1 -0
  185. package/dist/prompts/system/plan-execute.js +119 -0
  186. package/dist/prompts/system/plan-execute.js.map +1 -0
  187. package/dist/tools/browser/browser-client.d.ts +119 -0
  188. package/dist/tools/browser/browser-client.d.ts.map +1 -0
  189. package/dist/tools/browser/browser-client.js +1083 -0
  190. package/dist/tools/browser/browser-client.js.map +1 -0
  191. package/dist/tools/browser/browser-tools.d.ts +23 -0
  192. package/dist/tools/browser/browser-tools.d.ts.map +1 -0
  193. package/dist/tools/browser/browser-tools.js +1347 -0
  194. package/dist/tools/browser/browser-tools.js.map +1 -0
  195. package/dist/tools/browser/index.d.ts +7 -0
  196. package/dist/tools/browser/index.d.ts.map +1 -0
  197. package/dist/tools/browser/index.js +17 -0
  198. package/dist/tools/browser/index.js.map +1 -0
  199. package/dist/tools/index.d.ts +4 -0
  200. package/dist/tools/index.d.ts.map +1 -0
  201. package/dist/tools/index.js +4 -0
  202. package/dist/tools/index.js.map +1 -0
  203. package/dist/tools/llm/agents/docs-search-tools.d.ts +17 -0
  204. package/dist/tools/llm/agents/docs-search-tools.d.ts.map +1 -0
  205. package/dist/tools/llm/agents/docs-search-tools.js +265 -0
  206. package/dist/tools/llm/agents/docs-search-tools.js.map +1 -0
  207. package/dist/tools/llm/agents/index.d.ts +4 -0
  208. package/dist/tools/llm/agents/index.d.ts.map +1 -0
  209. package/dist/tools/llm/agents/index.js +3 -0
  210. package/dist/tools/llm/agents/index.js.map +1 -0
  211. package/dist/tools/llm/index.d.ts +3 -0
  212. package/dist/tools/llm/index.d.ts.map +1 -0
  213. package/dist/tools/llm/index.js +3 -0
  214. package/dist/tools/llm/index.js.map +1 -0
  215. package/dist/tools/llm/simple/ask-user-tool.d.ts +5 -0
  216. package/dist/tools/llm/simple/ask-user-tool.d.ts.map +1 -0
  217. package/dist/tools/llm/simple/ask-user-tool.js +7 -0
  218. package/dist/tools/llm/simple/ask-user-tool.js.map +1 -0
  219. package/dist/tools/llm/simple/background-bash-tool.d.ts +30 -0
  220. package/dist/tools/llm/simple/background-bash-tool.d.ts.map +1 -0
  221. package/dist/tools/llm/simple/background-bash-tool.js +320 -0
  222. package/dist/tools/llm/simple/background-bash-tool.js.map +1 -0
  223. package/dist/tools/llm/simple/background-powershell-tool.d.ts +30 -0
  224. package/dist/tools/llm/simple/background-powershell-tool.d.ts.map +1 -0
  225. package/dist/tools/llm/simple/background-powershell-tool.js +302 -0
  226. package/dist/tools/llm/simple/background-powershell-tool.js.map +1 -0
  227. package/dist/tools/llm/simple/bash-tool.d.ts +4 -0
  228. package/dist/tools/llm/simple/bash-tool.d.ts.map +1 -0
  229. package/dist/tools/llm/simple/bash-tool.js +167 -0
  230. package/dist/tools/llm/simple/bash-tool.js.map +1 -0
  231. package/dist/tools/llm/simple/docs-search-agent-tool.d.ts +6 -0
  232. package/dist/tools/llm/simple/docs-search-agent-tool.d.ts.map +1 -0
  233. package/dist/tools/llm/simple/docs-search-agent-tool.js +104 -0
  234. package/dist/tools/llm/simple/docs-search-agent-tool.js.map +1 -0
  235. package/dist/tools/llm/simple/file-tools.d.ts +13 -0
  236. package/dist/tools/llm/simple/file-tools.d.ts.map +1 -0
  237. package/dist/tools/llm/simple/file-tools.js +751 -0
  238. package/dist/tools/llm/simple/file-tools.js.map +1 -0
  239. package/dist/tools/llm/simple/final-response-tool.d.ts +12 -0
  240. package/dist/tools/llm/simple/final-response-tool.d.ts.map +1 -0
  241. package/dist/tools/llm/simple/final-response-tool.js +107 -0
  242. package/dist/tools/llm/simple/final-response-tool.js.map +1 -0
  243. package/dist/tools/llm/simple/index.d.ts +11 -0
  244. package/dist/tools/llm/simple/index.d.ts.map +1 -0
  245. package/dist/tools/llm/simple/index.js +20 -0
  246. package/dist/tools/llm/simple/index.js.map +1 -0
  247. package/dist/tools/llm/simple/planning-tools.d.ts +6 -0
  248. package/dist/tools/llm/simple/planning-tools.d.ts.map +1 -0
  249. package/dist/tools/llm/simple/planning-tools.js +171 -0
  250. package/dist/tools/llm/simple/planning-tools.js.map +1 -0
  251. package/dist/tools/llm/simple/powershell-tool.d.ts +4 -0
  252. package/dist/tools/llm/simple/powershell-tool.d.ts.map +1 -0
  253. package/dist/tools/llm/simple/powershell-tool.js +150 -0
  254. package/dist/tools/llm/simple/powershell-tool.js.map +1 -0
  255. package/dist/tools/llm/simple/simple-tool-executor.d.ts +38 -0
  256. package/dist/tools/llm/simple/simple-tool-executor.d.ts.map +1 -0
  257. package/dist/tools/llm/simple/simple-tool-executor.js +134 -0
  258. package/dist/tools/llm/simple/simple-tool-executor.js.map +1 -0
  259. package/dist/tools/llm/simple/todo-tools.d.ts +15 -0
  260. package/dist/tools/llm/simple/todo-tools.d.ts.map +1 -0
  261. package/dist/tools/llm/simple/todo-tools.js +145 -0
  262. package/dist/tools/llm/simple/todo-tools.js.map +1 -0
  263. package/dist/tools/llm/simple/user-interaction-tools.d.ts +22 -0
  264. package/dist/tools/llm/simple/user-interaction-tools.d.ts.map +1 -0
  265. package/dist/tools/llm/simple/user-interaction-tools.js +168 -0
  266. package/dist/tools/llm/simple/user-interaction-tools.js.map +1 -0
  267. package/dist/tools/office/common/constants.d.ts +194 -0
  268. package/dist/tools/office/common/constants.d.ts.map +1 -0
  269. package/dist/tools/office/common/constants.js +169 -0
  270. package/dist/tools/office/common/constants.js.map +1 -0
  271. package/dist/tools/office/common/index.d.ts +4 -0
  272. package/dist/tools/office/common/index.d.ts.map +1 -0
  273. package/dist/tools/office/common/index.js +3 -0
  274. package/dist/tools/office/common/index.js.map +1 -0
  275. package/dist/tools/office/common/types.d.ts +82 -0
  276. package/dist/tools/office/common/types.d.ts.map +1 -0
  277. package/dist/tools/office/common/types.js +2 -0
  278. package/dist/tools/office/common/types.js.map +1 -0
  279. package/dist/tools/office/common/utils.d.ts +14 -0
  280. package/dist/tools/office/common/utils.d.ts.map +1 -0
  281. package/dist/tools/office/common/utils.js +58 -0
  282. package/dist/tools/office/common/utils.js.map +1 -0
  283. package/dist/tools/office/excel-client.d.ts +212 -0
  284. package/dist/tools/office/excel-client.d.ts.map +1 -0
  285. package/dist/tools/office/excel-client.js +2242 -0
  286. package/dist/tools/office/excel-client.js.map +1 -0
  287. package/dist/tools/office/excel-tools/advanced.d.ts +13 -0
  288. package/dist/tools/office/excel-tools/advanced.d.ts.map +1 -0
  289. package/dist/tools/office/excel-tools/advanced.js +364 -0
  290. package/dist/tools/office/excel-tools/advanced.js.map +1 -0
  291. package/dist/tools/office/excel-tools/cells.d.ts +10 -0
  292. package/dist/tools/office/excel-tools/cells.d.ts.map +1 -0
  293. package/dist/tools/office/excel-tools/cells.js +279 -0
  294. package/dist/tools/office/excel-tools/cells.js.map +1 -0
  295. package/dist/tools/office/excel-tools/charts.d.ts +12 -0
  296. package/dist/tools/office/excel-tools/charts.d.ts.map +1 -0
  297. package/dist/tools/office/excel-tools/charts.js +373 -0
  298. package/dist/tools/office/excel-tools/charts.js.map +1 -0
  299. package/dist/tools/office/excel-tools/comments.d.ts +7 -0
  300. package/dist/tools/office/excel-tools/comments.d.ts.map +1 -0
  301. package/dist/tools/office/excel-tools/comments.js +150 -0
  302. package/dist/tools/office/excel-tools/comments.js.map +1 -0
  303. package/dist/tools/office/excel-tools/data-ops.d.ts +14 -0
  304. package/dist/tools/office/excel-tools/data-ops.d.ts.map +1 -0
  305. package/dist/tools/office/excel-tools/data-ops.js +420 -0
  306. package/dist/tools/office/excel-tools/data-ops.js.map +1 -0
  307. package/dist/tools/office/excel-tools/export.d.ts +8 -0
  308. package/dist/tools/office/excel-tools/export.d.ts.map +1 -0
  309. package/dist/tools/office/excel-tools/export.js +191 -0
  310. package/dist/tools/office/excel-tools/export.js.map +1 -0
  311. package/dist/tools/office/excel-tools/formatting.d.ts +12 -0
  312. package/dist/tools/office/excel-tools/formatting.d.ts.map +1 -0
  313. package/dist/tools/office/excel-tools/formatting.js +350 -0
  314. package/dist/tools/office/excel-tools/formatting.js.map +1 -0
  315. package/dist/tools/office/excel-tools/formulas.d.ts +11 -0
  316. package/dist/tools/office/excel-tools/formulas.d.ts.map +1 -0
  317. package/dist/tools/office/excel-tools/formulas.js +313 -0
  318. package/dist/tools/office/excel-tools/formulas.js.map +1 -0
  319. package/dist/tools/office/excel-tools/index.d.ts +21 -0
  320. package/dist/tools/office/excel-tools/index.d.ts.map +1 -0
  321. package/dist/tools/office/excel-tools/index.js +57 -0
  322. package/dist/tools/office/excel-tools/index.js.map +1 -0
  323. package/dist/tools/office/excel-tools/launch.d.ts +10 -0
  324. package/dist/tools/office/excel-tools/launch.d.ts.map +1 -0
  325. package/dist/tools/office/excel-tools/launch.js +248 -0
  326. package/dist/tools/office/excel-tools/launch.js.map +1 -0
  327. package/dist/tools/office/excel-tools/media.d.ts +10 -0
  328. package/dist/tools/office/excel-tools/media.d.ts.map +1 -0
  329. package/dist/tools/office/excel-tools/media.js +260 -0
  330. package/dist/tools/office/excel-tools/media.js.map +1 -0
  331. package/dist/tools/office/excel-tools/named-ranges.d.ts +6 -0
  332. package/dist/tools/office/excel-tools/named-ranges.d.ts.map +1 -0
  333. package/dist/tools/office/excel-tools/named-ranges.js +113 -0
  334. package/dist/tools/office/excel-tools/named-ranges.js.map +1 -0
  335. package/dist/tools/office/excel-tools/page-setup.d.ts +6 -0
  336. package/dist/tools/office/excel-tools/page-setup.d.ts.map +1 -0
  337. package/dist/tools/office/excel-tools/page-setup.js +144 -0
  338. package/dist/tools/office/excel-tools/page-setup.js.map +1 -0
  339. package/dist/tools/office/excel-tools/pivot-table.d.ts +7 -0
  340. package/dist/tools/office/excel-tools/pivot-table.d.ts.map +1 -0
  341. package/dist/tools/office/excel-tools/pivot-table.js +151 -0
  342. package/dist/tools/office/excel-tools/pivot-table.js.map +1 -0
  343. package/dist/tools/office/excel-tools/protection.d.ts +5 -0
  344. package/dist/tools/office/excel-tools/protection.d.ts.map +1 -0
  345. package/dist/tools/office/excel-tools/protection.js +75 -0
  346. package/dist/tools/office/excel-tools/protection.js.map +1 -0
  347. package/dist/tools/office/excel-tools/rows-columns.d.ts +15 -0
  348. package/dist/tools/office/excel-tools/rows-columns.d.ts.map +1 -0
  349. package/dist/tools/office/excel-tools/rows-columns.js +440 -0
  350. package/dist/tools/office/excel-tools/rows-columns.js.map +1 -0
  351. package/dist/tools/office/excel-tools/sheets.d.ts +16 -0
  352. package/dist/tools/office/excel-tools/sheets.d.ts.map +1 -0
  353. package/dist/tools/office/excel-tools/sheets.js +465 -0
  354. package/dist/tools/office/excel-tools/sheets.js.map +1 -0
  355. package/dist/tools/office/excel-tools/tables.d.ts +7 -0
  356. package/dist/tools/office/excel-tools/tables.d.ts.map +1 -0
  357. package/dist/tools/office/excel-tools/tables.js +151 -0
  358. package/dist/tools/office/excel-tools/tables.js.map +1 -0
  359. package/dist/tools/office/excel-tools/validation.d.ts +7 -0
  360. package/dist/tools/office/excel-tools/validation.d.ts.map +1 -0
  361. package/dist/tools/office/excel-tools/validation.js +175 -0
  362. package/dist/tools/office/excel-tools/validation.js.map +1 -0
  363. package/dist/tools/office/excel-tools.d.ts +3 -0
  364. package/dist/tools/office/excel-tools.d.ts.map +1 -0
  365. package/dist/tools/office/excel-tools.js +3 -0
  366. package/dist/tools/office/excel-tools.js.map +1 -0
  367. package/dist/tools/office/index.d.ts +6 -0
  368. package/dist/tools/office/index.d.ts.map +1 -0
  369. package/dist/tools/office/index.js +9 -0
  370. package/dist/tools/office/index.js.map +1 -0
  371. package/dist/tools/office/office-client-base.d.ts +31 -0
  372. package/dist/tools/office/office-client-base.d.ts.map +1 -0
  373. package/dist/tools/office/office-client-base.js +154 -0
  374. package/dist/tools/office/office-client-base.js.map +1 -0
  375. package/dist/tools/office/office-client.d.ts +196 -0
  376. package/dist/tools/office/office-client.d.ts.map +1 -0
  377. package/dist/tools/office/office-client.js +200 -0
  378. package/dist/tools/office/office-client.js.map +1 -0
  379. package/dist/tools/office/powerpoint-client.d.ts +155 -0
  380. package/dist/tools/office/powerpoint-client.d.ts.map +1 -0
  381. package/dist/tools/office/powerpoint-client.js +1359 -0
  382. package/dist/tools/office/powerpoint-client.js.map +1 -0
  383. package/dist/tools/office/powerpoint-tools/effects.d.ts +9 -0
  384. package/dist/tools/office/powerpoint-tools/effects.d.ts.map +1 -0
  385. package/dist/tools/office/powerpoint-tools/effects.js +259 -0
  386. package/dist/tools/office/powerpoint-tools/effects.js.map +1 -0
  387. package/dist/tools/office/powerpoint-tools/export.d.ts +7 -0
  388. package/dist/tools/office/powerpoint-tools/export.d.ts.map +1 -0
  389. package/dist/tools/office/powerpoint-tools/export.js +151 -0
  390. package/dist/tools/office/powerpoint-tools/export.js.map +1 -0
  391. package/dist/tools/office/powerpoint-tools/index.d.ts +13 -0
  392. package/dist/tools/office/powerpoint-tools/index.d.ts.map +1 -0
  393. package/dist/tools/office/powerpoint-tools/index.js +33 -0
  394. package/dist/tools/office/powerpoint-tools/index.js.map +1 -0
  395. package/dist/tools/office/powerpoint-tools/launch.d.ts +9 -0
  396. package/dist/tools/office/powerpoint-tools/launch.d.ts.map +1 -0
  397. package/dist/tools/office/powerpoint-tools/launch.js +214 -0
  398. package/dist/tools/office/powerpoint-tools/launch.js.map +1 -0
  399. package/dist/tools/office/powerpoint-tools/media.d.ts +8 -0
  400. package/dist/tools/office/powerpoint-tools/media.d.ts.map +1 -0
  401. package/dist/tools/office/powerpoint-tools/media.js +221 -0
  402. package/dist/tools/office/powerpoint-tools/media.js.map +1 -0
  403. package/dist/tools/office/powerpoint-tools/notes.d.ts +8 -0
  404. package/dist/tools/office/powerpoint-tools/notes.d.ts.map +1 -0
  405. package/dist/tools/office/powerpoint-tools/notes.js +181 -0
  406. package/dist/tools/office/powerpoint-tools/notes.js.map +1 -0
  407. package/dist/tools/office/powerpoint-tools/sections.d.ts +6 -0
  408. package/dist/tools/office/powerpoint-tools/sections.d.ts.map +1 -0
  409. package/dist/tools/office/powerpoint-tools/sections.js +111 -0
  410. package/dist/tools/office/powerpoint-tools/sections.js.map +1 -0
  411. package/dist/tools/office/powerpoint-tools/shapes.d.ts +24 -0
  412. package/dist/tools/office/powerpoint-tools/shapes.d.ts.map +1 -0
  413. package/dist/tools/office/powerpoint-tools/shapes.js +817 -0
  414. package/dist/tools/office/powerpoint-tools/shapes.js.map +1 -0
  415. package/dist/tools/office/powerpoint-tools/slides.d.ts +15 -0
  416. package/dist/tools/office/powerpoint-tools/slides.d.ts.map +1 -0
  417. package/dist/tools/office/powerpoint-tools/slides.js +447 -0
  418. package/dist/tools/office/powerpoint-tools/slides.js.map +1 -0
  419. package/dist/tools/office/powerpoint-tools/tables.d.ts +12 -0
  420. package/dist/tools/office/powerpoint-tools/tables.d.ts.map +1 -0
  421. package/dist/tools/office/powerpoint-tools/tables.js +362 -0
  422. package/dist/tools/office/powerpoint-tools/tables.js.map +1 -0
  423. package/dist/tools/office/powerpoint-tools/text.d.ts +13 -0
  424. package/dist/tools/office/powerpoint-tools/text.d.ts.map +1 -0
  425. package/dist/tools/office/powerpoint-tools/text.js +428 -0
  426. package/dist/tools/office/powerpoint-tools/text.js.map +1 -0
  427. package/dist/tools/office/powerpoint-tools.d.ts +3 -0
  428. package/dist/tools/office/powerpoint-tools.d.ts.map +1 -0
  429. package/dist/tools/office/powerpoint-tools.js +3 -0
  430. package/dist/tools/office/powerpoint-tools.js.map +1 -0
  431. package/dist/tools/office/word-client.d.ts +147 -0
  432. package/dist/tools/office/word-client.d.ts.map +1 -0
  433. package/dist/tools/office/word-client.js +1341 -0
  434. package/dist/tools/office/word-client.js.map +1 -0
  435. package/dist/tools/office/word-tools/bookmarks.d.ts +7 -0
  436. package/dist/tools/office/word-tools/bookmarks.d.ts.map +1 -0
  437. package/dist/tools/office/word-tools/bookmarks.js +146 -0
  438. package/dist/tools/office/word-tools/bookmarks.js.map +1 -0
  439. package/dist/tools/office/word-tools/comments.d.ts +7 -0
  440. package/dist/tools/office/word-tools/comments.d.ts.map +1 -0
  441. package/dist/tools/office/word-tools/comments.js +146 -0
  442. package/dist/tools/office/word-tools/comments.js.map +1 -0
  443. package/dist/tools/office/word-tools/content.d.ts +7 -0
  444. package/dist/tools/office/word-tools/content.d.ts.map +1 -0
  445. package/dist/tools/office/word-tools/content.js +168 -0
  446. package/dist/tools/office/word-tools/content.js.map +1 -0
  447. package/dist/tools/office/word-tools/export.d.ts +5 -0
  448. package/dist/tools/office/word-tools/export.d.ts.map +1 -0
  449. package/dist/tools/office/word-tools/export.js +73 -0
  450. package/dist/tools/office/word-tools/export.js.map +1 -0
  451. package/dist/tools/office/word-tools/find.d.ts +5 -0
  452. package/dist/tools/office/word-tools/find.d.ts.map +1 -0
  453. package/dist/tools/office/word-tools/find.js +106 -0
  454. package/dist/tools/office/word-tools/find.js.map +1 -0
  455. package/dist/tools/office/word-tools/footnotes.d.ts +9 -0
  456. package/dist/tools/office/word-tools/footnotes.d.ts.map +1 -0
  457. package/dist/tools/office/word-tools/footnotes.js +227 -0
  458. package/dist/tools/office/word-tools/footnotes.js.map +1 -0
  459. package/dist/tools/office/word-tools/formatting.d.ts +6 -0
  460. package/dist/tools/office/word-tools/formatting.d.ts.map +1 -0
  461. package/dist/tools/office/word-tools/formatting.js +129 -0
  462. package/dist/tools/office/word-tools/formatting.js.map +1 -0
  463. package/dist/tools/office/word-tools/headers-footers.d.ts +6 -0
  464. package/dist/tools/office/word-tools/headers-footers.d.ts.map +1 -0
  465. package/dist/tools/office/word-tools/headers-footers.js +117 -0
  466. package/dist/tools/office/word-tools/headers-footers.js.map +1 -0
  467. package/dist/tools/office/word-tools/index.d.ts +22 -0
  468. package/dist/tools/office/word-tools/index.d.ts.map +1 -0
  469. package/dist/tools/office/word-tools/index.js +63 -0
  470. package/dist/tools/office/word-tools/index.js.map +1 -0
  471. package/dist/tools/office/word-tools/launch.d.ts +10 -0
  472. package/dist/tools/office/word-tools/launch.d.ts.map +1 -0
  473. package/dist/tools/office/word-tools/launch.js +255 -0
  474. package/dist/tools/office/word-tools/launch.js.map +1 -0
  475. package/dist/tools/office/word-tools/lists.d.ts +5 -0
  476. package/dist/tools/office/word-tools/lists.d.ts.map +1 -0
  477. package/dist/tools/office/word-tools/lists.js +73 -0
  478. package/dist/tools/office/word-tools/lists.js.map +1 -0
  479. package/dist/tools/office/word-tools/navigation.d.ts +5 -0
  480. package/dist/tools/office/word-tools/navigation.d.ts.map +1 -0
  481. package/dist/tools/office/word-tools/navigation.js +85 -0
  482. package/dist/tools/office/word-tools/navigation.js.map +1 -0
  483. package/dist/tools/office/word-tools/page-setup.d.ts +7 -0
  484. package/dist/tools/office/word-tools/page-setup.d.ts.map +1 -0
  485. package/dist/tools/office/word-tools/page-setup.js +152 -0
  486. package/dist/tools/office/word-tools/page-setup.js.map +1 -0
  487. package/dist/tools/office/word-tools/selection.d.ts +8 -0
  488. package/dist/tools/office/word-tools/selection.d.ts.map +1 -0
  489. package/dist/tools/office/word-tools/selection.js +193 -0
  490. package/dist/tools/office/word-tools/selection.js.map +1 -0
  491. package/dist/tools/office/word-tools/tables-advanced.d.ts +8 -0
  492. package/dist/tools/office/word-tools/tables-advanced.d.ts.map +1 -0
  493. package/dist/tools/office/word-tools/tables-advanced.js +190 -0
  494. package/dist/tools/office/word-tools/tables-advanced.js.map +1 -0
  495. package/dist/tools/office/word-tools/tables.d.ts +8 -0
  496. package/dist/tools/office/word-tools/tables.d.ts.map +1 -0
  497. package/dist/tools/office/word-tools/tables.js +197 -0
  498. package/dist/tools/office/word-tools/tables.js.map +1 -0
  499. package/dist/tools/office/word-tools/text.d.ts +9 -0
  500. package/dist/tools/office/word-tools/text.d.ts.map +1 -0
  501. package/dist/tools/office/word-tools/text.js +235 -0
  502. package/dist/tools/office/word-tools/text.js.map +1 -0
  503. package/dist/tools/office/word-tools/toc.d.ts +6 -0
  504. package/dist/tools/office/word-tools/toc.d.ts.map +1 -0
  505. package/dist/tools/office/word-tools/toc.js +114 -0
  506. package/dist/tools/office/word-tools/toc.js.map +1 -0
  507. package/dist/tools/office/word-tools/track-changes.d.ts +8 -0
  508. package/dist/tools/office/word-tools/track-changes.d.ts.map +1 -0
  509. package/dist/tools/office/word-tools/track-changes.js +195 -0
  510. package/dist/tools/office/word-tools/track-changes.js.map +1 -0
  511. package/dist/tools/office/word-tools/undo-redo.d.ts +5 -0
  512. package/dist/tools/office/word-tools/undo-redo.d.ts.map +1 -0
  513. package/dist/tools/office/word-tools/undo-redo.js +73 -0
  514. package/dist/tools/office/word-tools/undo-redo.js.map +1 -0
  515. package/dist/tools/office/word-tools/watermarks.d.ts +5 -0
  516. package/dist/tools/office/word-tools/watermarks.d.ts.map +1 -0
  517. package/dist/tools/office/word-tools/watermarks.js +81 -0
  518. package/dist/tools/office/word-tools/watermarks.js.map +1 -0
  519. package/dist/tools/office/word-tools.d.ts +3 -0
  520. package/dist/tools/office/word-tools.d.ts.map +1 -0
  521. package/dist/tools/office/word-tools.js +3 -0
  522. package/dist/tools/office/word-tools.js.map +1 -0
  523. package/dist/tools/registry.d.ts +53 -0
  524. package/dist/tools/registry.d.ts.map +1 -0
  525. package/dist/tools/registry.js +282 -0
  526. package/dist/tools/registry.js.map +1 -0
  527. package/dist/tools/types.d.ts +88 -0
  528. package/dist/tools/types.d.ts.map +1 -0
  529. package/dist/tools/types.js +19 -0
  530. package/dist/tools/types.js.map +1 -0
  531. package/dist/types/index.d.ts +123 -0
  532. package/dist/types/index.d.ts.map +1 -0
  533. package/dist/types/index.js +2 -0
  534. package/dist/types/index.js.map +1 -0
  535. package/dist/ui/PlanExecuteView.d.ts +11 -0
  536. package/dist/ui/PlanExecuteView.d.ts.map +1 -0
  537. package/dist/ui/PlanExecuteView.js +27 -0
  538. package/dist/ui/PlanExecuteView.js.map +1 -0
  539. package/dist/ui/TodoPanel.d.ts +13 -0
  540. package/dist/ui/TodoPanel.d.ts.map +1 -0
  541. package/dist/ui/TodoPanel.js +135 -0
  542. package/dist/ui/TodoPanel.js.map +1 -0
  543. package/dist/ui/UpdateNotification.d.ts +13 -0
  544. package/dist/ui/UpdateNotification.d.ts.map +1 -0
  545. package/dist/ui/UpdateNotification.js +42 -0
  546. package/dist/ui/UpdateNotification.js.map +1 -0
  547. package/dist/ui/components/ActivityIndicator.d.ts +25 -0
  548. package/dist/ui/components/ActivityIndicator.d.ts.map +1 -0
  549. package/dist/ui/components/ActivityIndicator.js +115 -0
  550. package/dist/ui/components/ActivityIndicator.js.map +1 -0
  551. package/dist/ui/components/CommandBrowser.d.ts +10 -0
  552. package/dist/ui/components/CommandBrowser.d.ts.map +1 -0
  553. package/dist/ui/components/CommandBrowser.js +53 -0
  554. package/dist/ui/components/CommandBrowser.js.map +1 -0
  555. package/dist/ui/components/CustomTextInput.d.ts +13 -0
  556. package/dist/ui/components/CustomTextInput.d.ts.map +1 -0
  557. package/dist/ui/components/CustomTextInput.js +245 -0
  558. package/dist/ui/components/CustomTextInput.js.map +1 -0
  559. package/dist/ui/components/DocsSearchProgress.d.ts +13 -0
  560. package/dist/ui/components/DocsSearchProgress.d.ts.map +1 -0
  561. package/dist/ui/components/DocsSearchProgress.js +37 -0
  562. package/dist/ui/components/DocsSearchProgress.js.map +1 -0
  563. package/dist/ui/components/FileBrowser.d.ts +11 -0
  564. package/dist/ui/components/FileBrowser.d.ts.map +1 -0
  565. package/dist/ui/components/FileBrowser.js +45 -0
  566. package/dist/ui/components/FileBrowser.js.map +1 -0
  567. package/dist/ui/components/LLMSetupWizard.d.ts +8 -0
  568. package/dist/ui/components/LLMSetupWizard.d.ts.map +1 -0
  569. package/dist/ui/components/LLMSetupWizard.js +183 -0
  570. package/dist/ui/components/LLMSetupWizard.js.map +1 -0
  571. package/dist/ui/components/Logo.d.ts +21 -0
  572. package/dist/ui/components/Logo.d.ts.map +1 -0
  573. package/dist/ui/components/Logo.js +110 -0
  574. package/dist/ui/components/Logo.js.map +1 -0
  575. package/dist/ui/components/MarkdownRenderer.d.ts +9 -0
  576. package/dist/ui/components/MarkdownRenderer.d.ts.map +1 -0
  577. package/dist/ui/components/MarkdownRenderer.js +198 -0
  578. package/dist/ui/components/MarkdownRenderer.js.map +1 -0
  579. package/dist/ui/components/ModelSelector.d.ts +8 -0
  580. package/dist/ui/components/ModelSelector.d.ts.map +1 -0
  581. package/dist/ui/components/ModelSelector.js +111 -0
  582. package/dist/ui/components/ModelSelector.js.map +1 -0
  583. package/dist/ui/components/PlanExecuteApp.d.ts +23 -0
  584. package/dist/ui/components/PlanExecuteApp.d.ts.map +1 -0
  585. package/dist/ui/components/PlanExecuteApp.js +1433 -0
  586. package/dist/ui/components/PlanExecuteApp.js.map +1 -0
  587. package/dist/ui/components/ProgressBar.d.ts +10 -0
  588. package/dist/ui/components/ProgressBar.d.ts.map +1 -0
  589. package/dist/ui/components/ProgressBar.js +26 -0
  590. package/dist/ui/components/ProgressBar.js.map +1 -0
  591. package/dist/ui/components/StatusBar.d.ts +23 -0
  592. package/dist/ui/components/StatusBar.d.ts.map +1 -0
  593. package/dist/ui/components/StatusBar.js +162 -0
  594. package/dist/ui/components/StatusBar.js.map +1 -0
  595. package/dist/ui/components/ThinkingIndicator.d.ts +14 -0
  596. package/dist/ui/components/ThinkingIndicator.d.ts.map +1 -0
  597. package/dist/ui/components/ThinkingIndicator.js +63 -0
  598. package/dist/ui/components/ThinkingIndicator.js.map +1 -0
  599. package/dist/ui/components/TodoListView.d.ts +11 -0
  600. package/dist/ui/components/TodoListView.d.ts.map +1 -0
  601. package/dist/ui/components/TodoListView.js +69 -0
  602. package/dist/ui/components/TodoListView.js.map +1 -0
  603. package/dist/ui/components/ToolSelector.d.ts +7 -0
  604. package/dist/ui/components/ToolSelector.d.ts.map +1 -0
  605. package/dist/ui/components/ToolSelector.js +112 -0
  606. package/dist/ui/components/ToolSelector.js.map +1 -0
  607. package/dist/ui/components/dialogs/ApprovalDialog.d.ts +13 -0
  608. package/dist/ui/components/dialogs/ApprovalDialog.d.ts.map +1 -0
  609. package/dist/ui/components/dialogs/ApprovalDialog.js +173 -0
  610. package/dist/ui/components/dialogs/ApprovalDialog.js.map +1 -0
  611. package/dist/ui/components/dialogs/AskUserDialog.d.ts +9 -0
  612. package/dist/ui/components/dialogs/AskUserDialog.d.ts.map +1 -0
  613. package/dist/ui/components/dialogs/AskUserDialog.js +111 -0
  614. package/dist/ui/components/dialogs/AskUserDialog.js.map +1 -0
  615. package/dist/ui/components/dialogs/DocsBrowser.d.ts +8 -0
  616. package/dist/ui/components/dialogs/DocsBrowser.d.ts.map +1 -0
  617. package/dist/ui/components/dialogs/DocsBrowser.js +127 -0
  618. package/dist/ui/components/dialogs/DocsBrowser.js.map +1 -0
  619. package/dist/ui/components/dialogs/SettingsDialog.d.ts +10 -0
  620. package/dist/ui/components/dialogs/SettingsDialog.d.ts.map +1 -0
  621. package/dist/ui/components/dialogs/SettingsDialog.js +563 -0
  622. package/dist/ui/components/dialogs/SettingsDialog.js.map +1 -0
  623. package/dist/ui/components/dialogs/index.d.ts +4 -0
  624. package/dist/ui/components/dialogs/index.d.ts.map +1 -0
  625. package/dist/ui/components/dialogs/index.js +4 -0
  626. package/dist/ui/components/dialogs/index.js.map +1 -0
  627. package/dist/ui/components/index.d.ts +12 -0
  628. package/dist/ui/components/index.d.ts.map +1 -0
  629. package/dist/ui/components/index.js +9 -0
  630. package/dist/ui/components/index.js.map +1 -0
  631. package/dist/ui/components/panels/LogPanel.d.ts +7 -0
  632. package/dist/ui/components/panels/LogPanel.d.ts.map +1 -0
  633. package/dist/ui/components/panels/LogPanel.js +280 -0
  634. package/dist/ui/components/panels/LogPanel.js.map +1 -0
  635. package/dist/ui/components/panels/SessionPanel.d.ts +8 -0
  636. package/dist/ui/components/panels/SessionPanel.d.ts.map +1 -0
  637. package/dist/ui/components/panels/SessionPanel.js +81 -0
  638. package/dist/ui/components/panels/SessionPanel.js.map +1 -0
  639. package/dist/ui/components/panels/index.d.ts +4 -0
  640. package/dist/ui/components/panels/index.d.ts.map +1 -0
  641. package/dist/ui/components/panels/index.js +4 -0
  642. package/dist/ui/components/panels/index.js.map +1 -0
  643. package/dist/ui/components/views/ChatView.d.ts +12 -0
  644. package/dist/ui/components/views/ChatView.d.ts.map +1 -0
  645. package/dist/ui/components/views/ChatView.js +289 -0
  646. package/dist/ui/components/views/ChatView.js.map +1 -0
  647. package/dist/ui/components/views/index.d.ts +2 -0
  648. package/dist/ui/components/views/index.d.ts.map +1 -0
  649. package/dist/ui/components/views/index.js +2 -0
  650. package/dist/ui/components/views/index.js.map +1 -0
  651. package/dist/ui/contexts/TokenContext.d.ts +29 -0
  652. package/dist/ui/contexts/TokenContext.d.ts.map +1 -0
  653. package/dist/ui/contexts/TokenContext.js +79 -0
  654. package/dist/ui/contexts/TokenContext.js.map +1 -0
  655. package/dist/ui/hooks/atFileProcessor.d.ts +15 -0
  656. package/dist/ui/hooks/atFileProcessor.d.ts.map +1 -0
  657. package/dist/ui/hooks/atFileProcessor.js +88 -0
  658. package/dist/ui/hooks/atFileProcessor.js.map +1 -0
  659. package/dist/ui/hooks/index.d.ts +8 -0
  660. package/dist/ui/hooks/index.d.ts.map +1 -0
  661. package/dist/ui/hooks/index.js +8 -0
  662. package/dist/ui/hooks/index.js.map +1 -0
  663. package/dist/ui/hooks/slashCommandProcessor.d.ts +21 -0
  664. package/dist/ui/hooks/slashCommandProcessor.d.ts.map +1 -0
  665. package/dist/ui/hooks/slashCommandProcessor.js +100 -0
  666. package/dist/ui/hooks/slashCommandProcessor.js.map +1 -0
  667. package/dist/ui/hooks/useCommandBrowserState.d.ts +12 -0
  668. package/dist/ui/hooks/useCommandBrowserState.d.ts.map +1 -0
  669. package/dist/ui/hooks/useCommandBrowserState.js +66 -0
  670. package/dist/ui/hooks/useCommandBrowserState.js.map +1 -0
  671. package/dist/ui/hooks/useFileBrowserState.d.ts +15 -0
  672. package/dist/ui/hooks/useFileBrowserState.d.ts.map +1 -0
  673. package/dist/ui/hooks/useFileBrowserState.js +80 -0
  674. package/dist/ui/hooks/useFileBrowserState.js.map +1 -0
  675. package/dist/ui/hooks/useFileList.d.ts +20 -0
  676. package/dist/ui/hooks/useFileList.d.ts.map +1 -0
  677. package/dist/ui/hooks/useFileList.js +57 -0
  678. package/dist/ui/hooks/useFileList.js.map +1 -0
  679. package/dist/ui/hooks/useInputHistory.d.ts +9 -0
  680. package/dist/ui/hooks/useInputHistory.d.ts.map +1 -0
  681. package/dist/ui/hooks/useInputHistory.js +68 -0
  682. package/dist/ui/hooks/useInputHistory.js.map +1 -0
  683. package/dist/ui/hooks/usePlanExecution.d.ts +8 -0
  684. package/dist/ui/hooks/usePlanExecution.d.ts.map +1 -0
  685. package/dist/ui/hooks/usePlanExecution.js +208 -0
  686. package/dist/ui/hooks/usePlanExecution.js.map +1 -0
  687. package/dist/ui/index.d.ts +7 -0
  688. package/dist/ui/index.d.ts.map +1 -0
  689. package/dist/ui/index.js +7 -0
  690. package/dist/ui/index.js.map +1 -0
  691. package/dist/ui/ink-entry.d.ts +3 -0
  692. package/dist/ui/ink-entry.d.ts.map +1 -0
  693. package/dist/ui/ink-entry.js +22 -0
  694. package/dist/ui/ink-entry.js.map +1 -0
  695. package/dist/utils/file-system.d.ts +9 -0
  696. package/dist/utils/file-system.d.ts.map +1 -0
  697. package/dist/utils/file-system.js +99 -0
  698. package/dist/utils/file-system.js.map +1 -0
  699. package/dist/utils/git-utils.d.ts +2 -0
  700. package/dist/utils/git-utils.d.ts.map +1 -0
  701. package/dist/utils/git-utils.js +16 -0
  702. package/dist/utils/git-utils.js.map +1 -0
  703. package/dist/utils/json-stream-logger.d.ts +74 -0
  704. package/dist/utils/json-stream-logger.d.ts.map +1 -0
  705. package/dist/utils/json-stream-logger.js +808 -0
  706. package/dist/utils/json-stream-logger.js.map +1 -0
  707. package/dist/utils/logger.d.ts +152 -0
  708. package/dist/utils/logger.d.ts.map +1 -0
  709. package/dist/utils/logger.js +1672 -0
  710. package/dist/utils/logger.js.map +1 -0
  711. package/dist/utils/platform-utils.d.ts +19 -0
  712. package/dist/utils/platform-utils.d.ts.map +1 -0
  713. package/dist/utils/platform-utils.js +134 -0
  714. package/dist/utils/platform-utils.js.map +1 -0
  715. package/dist/utils/wsl-utils.d.ts +4 -0
  716. package/dist/utils/wsl-utils.d.ts.map +1 -0
  717. package/dist/utils/wsl-utils.js +72 -0
  718. package/dist/utils/wsl-utils.js.map +1 -0
  719. package/package.json +148 -0
  720. package/scripts/patch-yoga.js +48 -0
@@ -0,0 +1,2242 @@
1
+ import { OfficeClientBase } from './office-client-base.js';
2
+ function columnLetterToNumber(column) {
3
+ let result = 0;
4
+ for (let i = 0; i < column.length; i++) {
5
+ result = result * 26 + (column.charCodeAt(i) - 'A'.charCodeAt(0) + 1);
6
+ }
7
+ return result;
8
+ }
9
+ function columnNumberToLetter(num) {
10
+ if (num < 1) {
11
+ throw new Error(`Invalid column number: ${num}. Must be >= 1`);
12
+ }
13
+ if (num > 16384) {
14
+ throw new Error(`Invalid column number: ${num}. Excel maximum is 16384 (XFD)`);
15
+ }
16
+ let result = '';
17
+ while (num > 0) {
18
+ num--;
19
+ result = String.fromCharCode('A'.charCodeAt(0) + (num % 26)) + result;
20
+ num = Math.floor(num / 26);
21
+ }
22
+ return result;
23
+ }
24
+ function formatFormulaCriteria(criteria) {
25
+ const cellRefPattern = /&\$?[A-Z]+\$?\d+|&\$?[A-Z]+:\$?[A-Z]+/i;
26
+ if (cellRefPattern.test(criteria)) {
27
+ return criteria;
28
+ }
29
+ if (criteria.startsWith('"') && criteria.endsWith('"')) {
30
+ return criteria;
31
+ }
32
+ const escaped = criteria.replace(/"/g, '""');
33
+ return `"${escaped}"`;
34
+ }
35
+ export class ExcelClient extends OfficeClientBase {
36
+ async excelLaunch() {
37
+ return this.executePowerShell(`
38
+ try {
39
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
40
+ $excel.Visible = $true
41
+ @{ success = $true; message = "Connected to existing Excel instance" } | ConvertTo-Json -Compress
42
+ } catch {
43
+ $excel = New-Object -ComObject Excel.Application
44
+ $excel.Visible = $true
45
+ @{ success = $true; message = "Launched new Excel instance" } | ConvertTo-Json -Compress
46
+ }
47
+ `);
48
+ }
49
+ async excelCreate() {
50
+ return this.executePowerShell(`
51
+ try {
52
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
53
+ } catch {
54
+ $excel = New-Object -ComObject Excel.Application
55
+ $excel.Visible = $true
56
+ }
57
+ $workbook = $excel.Workbooks.Add()
58
+ @{ success = $true; message = "Created new workbook"; workbook_name = $workbook.Name } | ConvertTo-Json -Compress
59
+ `);
60
+ }
61
+ async excelOpen(filePath) {
62
+ const windowsPath = this.toWindowsPath(filePath).replace(/'/g, "''");
63
+ return this.executePowerShell(`
64
+ try {
65
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
66
+ } catch {
67
+ $excel = New-Object -ComObject Excel.Application
68
+ $excel.Visible = $true
69
+ }
70
+ $workbook = $excel.Workbooks.Open('${windowsPath}')
71
+ @{ success = $true; message = "Workbook opened"; workbook_name = $workbook.Name; path = $workbook.FullName } | ConvertTo-Json -Compress
72
+ `);
73
+ }
74
+ async excelWriteCell(cell, value, sheet, options) {
75
+ const strValue = String(value);
76
+ const escapedValue = strValue.replace(/'/g, "''");
77
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
78
+ const hasKorean = /[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(strValue);
79
+ const fontName = options?.fontName || (hasKorean ? 'Malgun Gothic' : '');
80
+ const fontScript = [];
81
+ if (fontName)
82
+ fontScript.push(`$range.Font.Name = '${fontName.replace(/'/g, "''")}'`);
83
+ if (options?.fontSize)
84
+ fontScript.push(`$range.Font.Size = ${options.fontSize}`);
85
+ if (options?.bold !== undefined)
86
+ fontScript.push(`$range.Font.Bold = ${options.bold ? '$true' : '$false'}`);
87
+ let valueScript;
88
+ if (options?.asText) {
89
+ valueScript = `$range.NumberFormat = '@'; $range.Value = '${escapedValue}'`;
90
+ }
91
+ else if (typeof value === 'number' || (strValue !== '' && !isNaN(Number(strValue)) && strValue.trim() !== '')) {
92
+ valueScript = `$range.Value = ${strValue}`;
93
+ }
94
+ else if (/^\d{4}-\d{2}-\d{2}$/.test(strValue)) {
95
+ const [year, month, day] = strValue.split('-');
96
+ valueScript = `$range.Value = (Get-Date -Year ${year} -Month ${month} -Day ${day}).ToOADate()`;
97
+ }
98
+ else if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(strValue)) {
99
+ valueScript = `$range.Value = '${escapedValue}'`;
100
+ }
101
+ else {
102
+ valueScript = `$range.Value = '${escapedValue}'`;
103
+ }
104
+ return this.executePowerShell(`
105
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
106
+ $workbook = $excel.ActiveWorkbook
107
+ ${sheetScript}
108
+ $range = $sheet.Range('${cell}')
109
+ ${valueScript}
110
+ ${fontScript.join('\n')}
111
+ @{ success = $true; message = "Value written to ${cell}" } | ConvertTo-Json -Compress
112
+ `);
113
+ }
114
+ async excelReadCell(cell, sheet) {
115
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
116
+ return this.executePowerShell(`
117
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
118
+ $workbook = $excel.ActiveWorkbook
119
+ ${sheetScript}
120
+ $value = $sheet.Range('${cell}').Value2
121
+ @{ success = $true; cell = '${cell}'; value = $value } | ConvertTo-Json -Compress
122
+ `);
123
+ }
124
+ async excelWriteRange(startCell, values, sheet) {
125
+ const rows = values.length;
126
+ const cols = values[0]?.length || 0;
127
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
128
+ let hasKorean = false;
129
+ const toPsValue = (v) => {
130
+ const str = String(v);
131
+ if (/[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(str))
132
+ hasKorean = true;
133
+ if (typeof v === 'number' || (str !== '' && !isNaN(Number(str)) && str.trim() !== '')) {
134
+ return str;
135
+ }
136
+ if (/^\d{4}-\d{2}-\d{2}$/.test(str)) {
137
+ const [year, month, day] = str.split('-');
138
+ return `([DateTime]::new(${year},${month},${day})).ToOADate()`;
139
+ }
140
+ return `'${str.replace(/'/g, "''")}'`;
141
+ };
142
+ const arrayLines = [];
143
+ for (let i = 0; i < values.length; i++) {
144
+ const row = values[i];
145
+ if (!row)
146
+ continue;
147
+ const rowValues = row.map(v => toPsValue(v)).join(',');
148
+ arrayLines.push(`@(${rowValues})`);
149
+ }
150
+ const arrayScript = `@(${arrayLines.join(',')})`;
151
+ const fontScript = hasKorean ? "$range.Font.Name = 'Malgun Gothic'" : '';
152
+ return this.executePowerShell(`
153
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
154
+ $workbook = $excel.ActiveWorkbook
155
+ ${sheetScript}
156
+ $startRange = $sheet.Range('${startCell}')
157
+ $endCell = $sheet.Cells($startRange.Row + ${rows - 1}, $startRange.Column + ${cols - 1})
158
+ $range = $sheet.Range($startRange, $endCell)
159
+ $data = ${arrayScript}
160
+ $range.Value = $data
161
+ ${fontScript}
162
+ @{ success = $true; message = "Range written from ${startCell} (${rows}x${cols})" } | ConvertTo-Json -Compress
163
+ `);
164
+ }
165
+ async excelReadRange(range, sheet) {
166
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
167
+ return this.executePowerShell(`
168
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
169
+ $workbook = $excel.ActiveWorkbook
170
+ ${sheetScript}
171
+ $range = $sheet.Range('${range}')
172
+ $values = $range.Value2
173
+ $rows = $range.Rows.Count
174
+ $cols = $range.Columns.Count
175
+ @{ success = $true; range = '${range}'; values = $values; rows = $rows; columns = $cols } | ConvertTo-Json -Compress -Depth 10
176
+ `);
177
+ }
178
+ async excelSave(filePath) {
179
+ const windowsPath = filePath ? this.toWindowsPath(filePath).replace(/'/g, "''") : '';
180
+ return this.executePowerShell(`
181
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
182
+ $workbook = $excel.ActiveWorkbook
183
+ ${windowsPath ? `$workbook.SaveAs('${windowsPath}')` : '$workbook.Save()'}
184
+ @{ success = $true; message = "Workbook saved"; path = $workbook.FullName } | ConvertTo-Json -Compress
185
+ `);
186
+ }
187
+ async excelClose(save = false) {
188
+ return this.executePowerShell(`
189
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
190
+ $workbook = $excel.ActiveWorkbook
191
+ $workbook.Close(${save ? '$true' : '$false'})
192
+ @{ success = $true; message = "Workbook closed" } | ConvertTo-Json -Compress
193
+ `);
194
+ }
195
+ async excelQuit(save = false) {
196
+ return this.executePowerShell(`
197
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
198
+ if (${save ? '$true' : '$false'}) {
199
+ foreach ($wb in $excel.Workbooks) { $wb.Save() }
200
+ }
201
+ $excel.Quit()
202
+ @{ success = $true; message = "Excel closed" } | ConvertTo-Json -Compress
203
+ `);
204
+ }
205
+ async excelSetFormula(cell, formula, sheet) {
206
+ const escapedFormula = formula.replace(/'/g, "''");
207
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
208
+ return this.executePowerShell(`
209
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
210
+ $workbook = $excel.ActiveWorkbook
211
+ ${sheetScript}
212
+ $sheet.Range('${cell}').Formula = '${escapedFormula}'
213
+ @{ success = $true; message = "Formula set in ${cell}" } | ConvertTo-Json -Compress
214
+ `);
215
+ }
216
+ async excelSetFont(range, options, sheet) {
217
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
218
+ const commands = [];
219
+ if (options.fontName)
220
+ commands.push(`$range.Font.Name = '${options.fontName.replace(/'/g, "''")}'`);
221
+ if (options.fontSize)
222
+ commands.push(`$range.Font.Size = ${options.fontSize}`);
223
+ if (options.bold !== undefined)
224
+ commands.push(`$range.Font.Bold = ${options.bold ? '$true' : '$false'}`);
225
+ if (options.italic !== undefined)
226
+ commands.push(`$range.Font.Italic = ${options.italic ? '$true' : '$false'}`);
227
+ if (options.underline !== undefined)
228
+ commands.push(`$range.Font.Underline = ${options.underline ? '2' : '0'}`);
229
+ if (options.color) {
230
+ const rgb = this.hexToRgb(options.color);
231
+ if (rgb)
232
+ commands.push(`$range.Font.Color = ${rgb.r + rgb.g * 256 + rgb.b * 65536}`);
233
+ }
234
+ return this.executePowerShell(`
235
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
236
+ $workbook = $excel.ActiveWorkbook
237
+ ${sheetScript}
238
+ $range = $sheet.Range('${range}')
239
+ ${commands.join('\n')}
240
+ @{ success = $true; message = "Font properties set for ${range}" } | ConvertTo-Json -Compress
241
+ `);
242
+ }
243
+ async excelSetAlignment(range, options, sheet) {
244
+ const hAlignMap = { left: -4131, center: -4108, right: -4152 };
245
+ const vAlignMap = { top: -4160, center: -4108, bottom: -4107 };
246
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
247
+ const commands = [];
248
+ if (options.horizontal)
249
+ commands.push(`$range.HorizontalAlignment = ${hAlignMap[options.horizontal]}`);
250
+ if (options.vertical)
251
+ commands.push(`$range.VerticalAlignment = ${vAlignMap[options.vertical]}`);
252
+ if (options.wrapText !== undefined)
253
+ commands.push(`$range.WrapText = ${options.wrapText ? '$true' : '$false'}`);
254
+ if (options.orientation !== undefined)
255
+ commands.push(`$range.Orientation = ${options.orientation}`);
256
+ return this.executePowerShell(`
257
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
258
+ $workbook = $excel.ActiveWorkbook
259
+ ${sheetScript}
260
+ $range = $sheet.Range('${range}')
261
+ ${commands.join('\n')}
262
+ @{ success = $true; message = "Alignment set for ${range}" } | ConvertTo-Json -Compress
263
+ `);
264
+ }
265
+ async excelSetColumnWidth(column, width, autoFit, sheet) {
266
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
267
+ return this.executePowerShell(`
268
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
269
+ $workbook = $excel.ActiveWorkbook
270
+ ${sheetScript}
271
+ $col = $sheet.Columns('${column}')
272
+ ${autoFit ? '$col.AutoFit()' : `$col.ColumnWidth = ${width || 10}`}
273
+ @{ success = $true; message = "Column ${column} width set" } | ConvertTo-Json -Compress
274
+ `);
275
+ }
276
+ async excelSetRowHeight(row, height, autoFit, sheet) {
277
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
278
+ return this.executePowerShell(`
279
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
280
+ $workbook = $excel.ActiveWorkbook
281
+ ${sheetScript}
282
+ $row = $sheet.Rows(${row})
283
+ ${autoFit ? '$row.AutoFit()' : `$row.RowHeight = ${height || 15}`}
284
+ @{ success = $true; message = "Row ${row} height set" } | ConvertTo-Json -Compress
285
+ `);
286
+ }
287
+ async excelMergeCells(range, sheet) {
288
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
289
+ return this.executePowerShell(`
290
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
291
+ $workbook = $excel.ActiveWorkbook
292
+ ${sheetScript}
293
+ $sheet.Range('${range}').Merge()
294
+ @{ success = $true; message = "Cells merged: ${range}" } | ConvertTo-Json -Compress
295
+ `);
296
+ }
297
+ async excelSetBorder(range, options, sheet) {
298
+ const styleMap = { thin: 1, medium: 1, thick: 1, double: -4119, dotted: -4118, dashed: -4115 };
299
+ const weightMap = { thin: 2, medium: -4138, thick: 4, double: 2, dotted: 2, dashed: 2 };
300
+ const edgeMap = { left: 7, right: 10, top: 8, bottom: 9, all: -1 };
301
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
302
+ const edges = options.edges || ['all'];
303
+ const borderStyle = options.style ? styleMap[options.style] : 1;
304
+ const borderWeight = options.style ? weightMap[options.style] : 2;
305
+ let borderScript = '';
306
+ if (edges.includes('all')) {
307
+ borderScript = `
308
+ $range.Borders.LineStyle = ${borderStyle}
309
+ $range.Borders.Weight = ${borderWeight}`;
310
+ }
311
+ else {
312
+ borderScript = edges.map(e => `$range.Borders(${edgeMap[e]}).LineStyle = ${borderStyle}
313
+ $range.Borders(${edgeMap[e]}).Weight = ${borderWeight}`).join('\n');
314
+ }
315
+ return this.executePowerShell(`
316
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
317
+ $workbook = $excel.ActiveWorkbook
318
+ ${sheetScript}
319
+ $range = $sheet.Range('${range}')
320
+ ${borderScript}
321
+ @{ success = $true; message = "Border set for ${range}" } | ConvertTo-Json -Compress
322
+ `);
323
+ }
324
+ async excelSetFill(range, color, sheet) {
325
+ const rgb = this.hexToRgb(color);
326
+ const colorValue = rgb ? rgb.r + rgb.g * 256 + rgb.b * 65536 : 0;
327
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
328
+ return this.executePowerShell(`
329
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
330
+ $workbook = $excel.ActiveWorkbook
331
+ ${sheetScript}
332
+ $sheet.Range('${range}').Interior.Color = ${colorValue}
333
+ @{ success = $true; message = "Fill color set for ${range}" } | ConvertTo-Json -Compress
334
+ `);
335
+ }
336
+ async excelSetNumberFormat(range, format, sheet) {
337
+ const escapedFormat = format.replace(/'/g, "''");
338
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
339
+ return this.executePowerShell(`
340
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
341
+ $workbook = $excel.ActiveWorkbook
342
+ ${sheetScript}
343
+ $sheet.Range('${range}').NumberFormat = '${escapedFormat}'
344
+ @{ success = $true; message = "Number format set for ${range}" } | ConvertTo-Json -Compress
345
+ `);
346
+ }
347
+ async excelAddSheet(name, position) {
348
+ const escapedName = name?.replace(/'/g, "''") || '';
349
+ let positionScript = '';
350
+ if (position === 'start') {
351
+ positionScript = ', [ref]$workbook.Sheets(1)';
352
+ }
353
+ else if (position === 'end') {
354
+ positionScript = ', , [ref]$workbook.Sheets($workbook.Sheets.Count)';
355
+ }
356
+ else if (position) {
357
+ positionScript = `, , [ref]$workbook.Sheets('${position.replace(/'/g, "''")}')`;
358
+ }
359
+ return this.executePowerShell(`
360
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
361
+ $workbook = $excel.ActiveWorkbook
362
+ $newSheet = $workbook.Sheets.Add(${positionScript})
363
+ ${escapedName ? `$newSheet.Name = '${escapedName}'` : ''}
364
+ @{ success = $true; message = "Sheet added"; sheet_name = $newSheet.Name } | ConvertTo-Json -Compress
365
+ `);
366
+ }
367
+ async excelDeleteSheet(name) {
368
+ const escapedName = name.replace(/'/g, "''");
369
+ return this.executePowerShell(`
370
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
371
+ $workbook = $excel.ActiveWorkbook
372
+ $excel.DisplayAlerts = $false
373
+ $workbook.Sheets('${escapedName}').Delete()
374
+ $excel.DisplayAlerts = $true
375
+ @{ success = $true; message = "Sheet '${escapedName}' deleted" } | ConvertTo-Json -Compress
376
+ `);
377
+ }
378
+ async excelRenameSheet(oldName, newName) {
379
+ const escapedOld = oldName.replace(/'/g, "''");
380
+ const escapedNew = newName.replace(/'/g, "''");
381
+ return this.executePowerShell(`
382
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
383
+ $workbook = $excel.ActiveWorkbook
384
+ $workbook.Sheets('${escapedOld}').Name = '${escapedNew}'
385
+ @{ success = $true; message = "Sheet renamed from '${escapedOld}' to '${escapedNew}'" } | ConvertTo-Json -Compress
386
+ `);
387
+ }
388
+ async excelCopySheet(sourceName, newName, position, targetSheet) {
389
+ if (newName) {
390
+ if (newName.length > 31) {
391
+ return { success: false, error: 'Sheet name cannot exceed 31 characters' };
392
+ }
393
+ if (/[:\\/?*\[\]]/.test(newName)) {
394
+ return { success: false, error: 'Sheet name cannot contain : \\ / ? * [ ]' };
395
+ }
396
+ }
397
+ const escapedSource = sourceName.replace(/'/g, "''");
398
+ const escapedNew = newName?.replace(/'/g, "''") || '';
399
+ const escapedTarget = targetSheet?.replace(/'/g, "''") || '';
400
+ let positionScript = '';
401
+ if (position === 'before' && targetSheet) {
402
+ positionScript = `$workbook.Sheets('${escapedSource}').Copy([ref]$workbook.Sheets('${escapedTarget}'))`;
403
+ }
404
+ else if (position === 'after' && targetSheet) {
405
+ positionScript = `$workbook.Sheets('${escapedSource}').Copy($null, [ref]$workbook.Sheets('${escapedTarget}'))`;
406
+ }
407
+ else if (position && !targetSheet) {
408
+ if (position === 'before') {
409
+ positionScript = `$workbook.Sheets('${escapedSource}').Copy([ref]$workbook.Sheets(1))`;
410
+ }
411
+ else {
412
+ positionScript = `$workbook.Sheets('${escapedSource}').Copy($null, [ref]$workbook.Sheets($workbook.Sheets.Count))`;
413
+ }
414
+ }
415
+ else {
416
+ positionScript = `$workbook.Sheets('${escapedSource}').Copy($null, [ref]$workbook.Sheets('${escapedSource}'))`;
417
+ }
418
+ return this.executePowerShell(`
419
+ try {
420
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
421
+ $workbook = $excel.ActiveWorkbook
422
+ if (-not $workbook.Sheets('${escapedSource}')) {
423
+ throw "Source sheet '${escapedSource}' not found"
424
+ }
425
+ ${positionScript}
426
+ $newSheet = $workbook.ActiveSheet
427
+ ${escapedNew ? `$newSheet.Name = '${escapedNew}'` : ''}
428
+ @{ success = $true; message = "Sheet copied"; new_sheet_name = $newSheet.Name } | ConvertTo-Json -Compress
429
+ } catch {
430
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
431
+ }
432
+ `);
433
+ }
434
+ async excelGetSheets() {
435
+ return this.executePowerShell(`
436
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
437
+ $workbook = $excel.ActiveWorkbook
438
+ $sheets = @()
439
+ foreach ($sheet in $workbook.Sheets) {
440
+ $sheets += $sheet.Name
441
+ }
442
+ @{ success = $true; sheets = $sheets; count = $sheets.Count } | ConvertTo-Json -Compress
443
+ `);
444
+ }
445
+ async excelSortRange(range, sortColumn, ascending = true, hasHeader = true, sheet) {
446
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
447
+ const order = ascending ? 1 : 2;
448
+ const header = hasHeader ? 1 : 2;
449
+ return this.executePowerShell(`
450
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
451
+ $workbook = $excel.ActiveWorkbook
452
+ ${sheetScript}
453
+ $range = $sheet.Range('${range}')
454
+ $sortKey = $sheet.Range('${sortColumn}1')
455
+
456
+ # Use Sort object for better compatibility
457
+ $sheet.Sort.SortFields.Clear()
458
+ $sheet.Sort.SortFields.Add($sortKey, 0, ${order})
459
+ $sheet.Sort.SetRange($range)
460
+ $sheet.Sort.Header = ${header}
461
+ $sheet.Sort.Apply()
462
+
463
+ @{ success = $true; message = "Range sorted by column ${sortColumn}" } | ConvertTo-Json -Compress
464
+ `);
465
+ }
466
+ async excelInsertRow(row, count = 1, sheet) {
467
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
468
+ return this.executePowerShell(`
469
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
470
+ $workbook = $excel.ActiveWorkbook
471
+ ${sheetScript}
472
+ for ($i = 0; $i -lt ${count}; $i++) {
473
+ $sheet.Rows(${row}).Insert()
474
+ }
475
+ @{ success = $true; message = "${count} row(s) inserted at row ${row}" } | ConvertTo-Json -Compress
476
+ `);
477
+ }
478
+ async excelDeleteRow(row, count = 1, sheet) {
479
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
480
+ return this.executePowerShell(`
481
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
482
+ $workbook = $excel.ActiveWorkbook
483
+ ${sheetScript}
484
+ $sheet.Rows("${row}:${row + count - 1}").Delete()
485
+ @{ success = $true; message = "${count} row(s) deleted starting at row ${row}" } | ConvertTo-Json -Compress
486
+ `);
487
+ }
488
+ async excelInsertColumn(column, count = 1, sheet) {
489
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
490
+ return this.executePowerShell(`
491
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
492
+ $workbook = $excel.ActiveWorkbook
493
+ ${sheetScript}
494
+ for ($i = 0; $i -lt ${count}; $i++) {
495
+ $sheet.Columns('${column}').Insert()
496
+ }
497
+ @{ success = $true; message = "${count} column(s) inserted at column ${column}" } | ConvertTo-Json -Compress
498
+ `);
499
+ }
500
+ async excelDeleteColumn(column, count = 1, sheet) {
501
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
502
+ const startColNum = columnLetterToNumber(column.toUpperCase());
503
+ const endCol = columnNumberToLetter(startColNum + count - 1);
504
+ return this.executePowerShell(`
505
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
506
+ $workbook = $excel.ActiveWorkbook
507
+ ${sheetScript}
508
+ $sheet.Columns("${column}:${endCol}").Delete()
509
+ @{ success = $true; message = "${count} column(s) deleted starting at column ${column}" } | ConvertTo-Json -Compress
510
+ `);
511
+ }
512
+ async excelFreezePanes(row, column, sheet) {
513
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
514
+ const cellRef = `${column || 'A'}${row || 1}`;
515
+ return this.executePowerShell(`
516
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
517
+ $workbook = $excel.ActiveWorkbook
518
+ ${sheetScript}
519
+ $sheet.Activate()
520
+ $sheet.Range('${cellRef}').Select()
521
+ $excel.ActiveWindow.FreezePanes = $true
522
+ @{ success = $true; message = "Panes frozen at ${cellRef}" } | ConvertTo-Json -Compress
523
+ `);
524
+ }
525
+ async excelAutoFilter(range, sheet) {
526
+ const sheetScript = sheet ? `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` : '$sheet = $workbook.ActiveSheet';
527
+ return this.executePowerShell(`
528
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
529
+ $workbook = $excel.ActiveWorkbook
530
+ ${sheetScript}
531
+ $sheet.Range('${range}').AutoFilter()
532
+ @{ success = $true; message = "AutoFilter applied to ${range}" } | ConvertTo-Json -Compress
533
+ `);
534
+ }
535
+ async excelScreenshot() {
536
+ const result = await this.executePowerShell(`
537
+ Add-Type -AssemblyName System.Windows.Forms
538
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
539
+ $sheet = $excel.ActiveWorkbook.ActiveSheet
540
+
541
+ # Get used range and copy as picture
542
+ $usedRange = $sheet.UsedRange
543
+ $usedRange.CopyPicture(1, 2) # xlScreen=1, xlBitmap=2
544
+
545
+ # Get image from clipboard
546
+ Start-Sleep -Milliseconds 500
547
+ $img = [System.Windows.Forms.Clipboard]::GetImage()
548
+ if ($img -eq $null) {
549
+ @{ success = $false; error = "Failed to capture screenshot" } | ConvertTo-Json -Compress
550
+ return
551
+ }
552
+
553
+ # Convert to base64
554
+ $ms = New-Object System.IO.MemoryStream
555
+ $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
556
+ $bytes = $ms.ToArray()
557
+ $base64 = [Convert]::ToBase64String($bytes)
558
+ $ms.Dispose()
559
+ $img.Dispose()
560
+
561
+ @{
562
+ success = $true
563
+ image = $base64
564
+ format = "png"
565
+ encoding = "base64"
566
+ } | ConvertTo-Json -Compress
567
+ `);
568
+ return result;
569
+ }
570
+ async excelAddChart(dataRange, chartType, options) {
571
+ const chartTypeMap = {
572
+ column: 51,
573
+ bar: 57,
574
+ line: 4,
575
+ pie: 5,
576
+ area: 1,
577
+ scatter: -4169,
578
+ doughnut: -4120,
579
+ };
580
+ const xlChartType = chartTypeMap[chartType] ?? 51;
581
+ const escapedTitle = options?.title?.replace(/'/g, "''") || '';
582
+ const hasKorean = options?.title ? /[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(options.title) : false;
583
+ const sheetScript = options?.sheet ?
584
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${options.sheet.replace(/'/g, "''")}')` :
585
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
586
+ const left = options?.left ?? 100;
587
+ const top = options?.top ?? 100;
588
+ const width = options?.width ?? 400;
589
+ const height = options?.height ?? 300;
590
+ const titleScript = escapedTitle ? `
591
+ $chart.HasTitle = $true
592
+ $chart.ChartTitle.Text = '${escapedTitle}'
593
+ ${hasKorean ? "$chart.ChartTitle.Font.Name = 'Malgun Gothic'" : ''}` : '';
594
+ const koreanFontScript = hasKorean ? `
595
+ # Apply Malgun Gothic to legend
596
+ if ($chart.HasLegend) {
597
+ $chart.Legend.Font.Name = 'Malgun Gothic'
598
+ }
599
+ # Apply to axis labels (Category and Value axes)
600
+ try {
601
+ $chart.Axes(1).TickLabels.Font.Name = 'Malgun Gothic' # xlCategory
602
+ $chart.Axes(2).TickLabels.Font.Name = 'Malgun Gothic' # xlValue
603
+ } catch { }` : '';
604
+ return this.executePowerShell(`
605
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
606
+ ${sheetScript}
607
+ $range = $sheet.Range('${dataRange}')
608
+ $chartObj = $sheet.ChartObjects().Add(${left}, ${top}, ${width}, ${height})
609
+ $chart = $chartObj.Chart
610
+ $chart.SetSourceData($range)
611
+ $chart.ChartType = ${xlChartType}
612
+ ${titleScript}
613
+ ${koreanFontScript}
614
+ @{ success = $true; message = "Chart added"; chart_name = $chartObj.Name } | ConvertTo-Json -Compress
615
+ `);
616
+ }
617
+ async excelSetChartTitle(chartIndex, title, sheet) {
618
+ const escapedTitle = title.replace(/'/g, "''");
619
+ const hasKorean = /[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(title);
620
+ const sheetScript = sheet ?
621
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
622
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
623
+ return this.executePowerShell(`
624
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
625
+ ${sheetScript}
626
+ $chartObj = $sheet.ChartObjects(${chartIndex})
627
+ $chart = $chartObj.Chart
628
+ $chart.HasTitle = $true
629
+ $chart.ChartTitle.Text = '${escapedTitle}'
630
+ ${hasKorean ? "$chart.ChartTitle.Font.Name = 'Malgun Gothic'" : ''}
631
+ @{ success = $true; message = "Chart title set" } | ConvertTo-Json -Compress
632
+ `);
633
+ }
634
+ async excelDeleteChart(chartIndex, sheet) {
635
+ const sheetScript = sheet ?
636
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
637
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
638
+ return this.executePowerShell(`
639
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
640
+ ${sheetScript}
641
+ $sheet.ChartObjects(${chartIndex}).Delete()
642
+ @{ success = $true; message = "Chart deleted" } | ConvertTo-Json -Compress
643
+ `);
644
+ }
645
+ async excelAddConditionalFormat(range, formatType, options) {
646
+ const sheetScript = options?.sheet ?
647
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${options.sheet.replace(/'/g, "''")}')` :
648
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
649
+ const typeMap = {
650
+ cellValue: 1,
651
+ colorScale: 3,
652
+ dataBar: 4,
653
+ iconSet: 6,
654
+ duplicates: 8,
655
+ top10: 5,
656
+ };
657
+ const conditionType = typeMap[formatType] ?? 1;
658
+ const operatorMap = {
659
+ greater: 5,
660
+ less: 6,
661
+ equal: 3,
662
+ between: 1,
663
+ notBetween: 2,
664
+ };
665
+ const xlOperator = options?.operator ? operatorMap[options.operator] : 5;
666
+ let formatScript = '';
667
+ if (formatType === 'cellValue') {
668
+ const formula1 = typeof options?.value1 === 'string' ? `"${options.value1}"` : options?.value1 ?? 0;
669
+ const formula2 = options?.value2 !== undefined ?
670
+ (typeof options.value2 === 'string' ? `"${options.value2}"` : options.value2) : '';
671
+ formatScript = `
672
+ $fc = $range.FormatConditions.Add(${conditionType}, ${xlOperator}, ${formula1}${formula2 ? `, ${formula2}` : ''})`;
673
+ if (options?.fillColor) {
674
+ const rgb = this.hexToRgb(options.fillColor);
675
+ if (rgb) {
676
+ formatScript += `\n$fc.Interior.Color = ${rgb.r + rgb.g * 256 + rgb.b * 65536}`;
677
+ }
678
+ }
679
+ if (options?.fontColor) {
680
+ const rgb = this.hexToRgb(options.fontColor);
681
+ if (rgb) {
682
+ formatScript += `\n$fc.Font.Color = ${rgb.r + rgb.g * 256 + rgb.b * 65536}`;
683
+ }
684
+ }
685
+ }
686
+ else if (formatType === 'colorScale') {
687
+ formatScript = '$range.FormatConditions.AddColorScale(3)';
688
+ }
689
+ else if (formatType === 'dataBar') {
690
+ formatScript = '$range.FormatConditions.AddDataBar()';
691
+ }
692
+ else if (formatType === 'iconSet') {
693
+ formatScript = '$range.FormatConditions.AddIconSetCondition()';
694
+ }
695
+ else if (formatType === 'duplicates') {
696
+ formatScript = `$fc = $range.FormatConditions.AddUniqueValues()
697
+ $fc.DupeUnique = 1`;
698
+ if (options?.fillColor) {
699
+ const rgb = this.hexToRgb(options.fillColor);
700
+ if (rgb) {
701
+ formatScript += `\n$fc.Interior.Color = ${rgb.r + rgb.g * 256 + rgb.b * 65536}`;
702
+ }
703
+ }
704
+ }
705
+ else if (formatType === 'top10') {
706
+ formatScript = `$fc = $range.FormatConditions.AddTop10()
707
+ $fc.TopBottom = 1
708
+ $fc.Rank = 10`;
709
+ if (options?.fillColor) {
710
+ const rgb = this.hexToRgb(options.fillColor);
711
+ if (rgb) {
712
+ formatScript += `\n$fc.Interior.Color = ${rgb.r + rgb.g * 256 + rgb.b * 65536}`;
713
+ }
714
+ }
715
+ }
716
+ return this.executePowerShell(`
717
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
718
+ ${sheetScript}
719
+ $range = $sheet.Range('${range}')
720
+ ${formatScript}
721
+ @{ success = $true; message = "Conditional format added to ${range}" } | ConvertTo-Json -Compress
722
+ `);
723
+ }
724
+ async excelClearConditionalFormat(range, sheet) {
725
+ const sheetScript = sheet ?
726
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
727
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
728
+ return this.executePowerShell(`
729
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
730
+ ${sheetScript}
731
+ $sheet.Range('${range}').FormatConditions.Delete()
732
+ @{ success = $true; message = "Conditional formatting cleared from ${range}" } | ConvertTo-Json -Compress
733
+ `);
734
+ }
735
+ async excelSetDataValidation(range, validationType, options) {
736
+ const sheetScript = options?.sheet ?
737
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${options.sheet.replace(/'/g, "''")}')` :
738
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
739
+ const typeMap = {
740
+ list: 3,
741
+ whole: 1,
742
+ decimal: 2,
743
+ date: 4,
744
+ textLength: 6,
745
+ custom: 7,
746
+ };
747
+ const dvType = typeMap[validationType] ?? 3;
748
+ const operatorMap = {
749
+ between: 1,
750
+ notBetween: 2,
751
+ equal: 3,
752
+ notEqual: 4,
753
+ greater: 5,
754
+ less: 6,
755
+ greaterEqual: 7,
756
+ lessEqual: 8,
757
+ };
758
+ const xlOperator = options.operator ? operatorMap[options.operator] : 1;
759
+ const formula1 = options.formula1?.replace(/'/g, "''") || '';
760
+ const formula2 = options.formula2?.replace(/'/g, "''") || '';
761
+ const additionalSettings = [];
762
+ if (options.showInputMessage !== false && (options.inputTitle || options.inputMessage)) {
763
+ additionalSettings.push('$validation.ShowInput = $true');
764
+ if (options.inputTitle)
765
+ additionalSettings.push(`$validation.InputTitle = '${options.inputTitle.replace(/'/g, "''")}'`);
766
+ if (options.inputMessage)
767
+ additionalSettings.push(`$validation.InputMessage = '${options.inputMessage.replace(/'/g, "''")}'`);
768
+ }
769
+ if (options.showErrorMessage !== false && (options.errorTitle || options.errorMessage)) {
770
+ additionalSettings.push('$validation.ShowError = $true');
771
+ if (options.errorTitle)
772
+ additionalSettings.push(`$validation.ErrorTitle = '${options.errorTitle.replace(/'/g, "''")}'`);
773
+ if (options.errorMessage)
774
+ additionalSettings.push(`$validation.ErrorMessage = '${options.errorMessage.replace(/'/g, "''")}'`);
775
+ }
776
+ const validationParams = validationType === 'list'
777
+ ? `${dvType}, 1, 1, '${formula1}'`
778
+ : `${dvType}, 1, ${xlOperator}, '${formula1}'${formula2 ? `, '${formula2}'` : ''}`;
779
+ return this.executePowerShell(`
780
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
781
+ ${sheetScript}
782
+ $range = $sheet.Range('${range}')
783
+ $range.Validation.Delete()
784
+ $range.Validation.Add(${validationParams})
785
+ $validation = $range.Validation
786
+ ${additionalSettings.join('\n')}
787
+ @{ success = $true; message = "Data validation set on ${range}" } | ConvertTo-Json -Compress
788
+ `);
789
+ }
790
+ async excelClearDataValidation(range, sheet) {
791
+ const sheetScript = sheet ?
792
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
793
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
794
+ return this.executePowerShell(`
795
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
796
+ ${sheetScript}
797
+ $sheet.Range('${range}').Validation.Delete()
798
+ @{ success = $true; message = "Data validation cleared from ${range}" } | ConvertTo-Json -Compress
799
+ `);
800
+ }
801
+ async excelCreateNamedRange(name, range, sheet) {
802
+ const escapedName = name.replace(/'/g, "''");
803
+ const sheetScript = sheet ?
804
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
805
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
806
+ return this.executePowerShell(`
807
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
808
+ $workbook = $excel.ActiveWorkbook
809
+ ${sheetScript}
810
+ $range = $sheet.Range('${range}')
811
+ $workbook.Names.Add('${escapedName}', $range)
812
+ @{ success = $true; message = "Named range '${escapedName}' created" } | ConvertTo-Json -Compress
813
+ `);
814
+ }
815
+ async excelGetNamedRanges() {
816
+ return this.executePowerShell(`
817
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
818
+ $workbook = $excel.ActiveWorkbook
819
+ $names = @()
820
+ foreach ($n in $workbook.Names) {
821
+ $names += @{
822
+ name = $n.Name
823
+ refersTo = $n.RefersTo
824
+ value = $n.Value
825
+ }
826
+ }
827
+ @{ success = $true; named_ranges = $names } | ConvertTo-Json -Compress -Depth 5
828
+ `);
829
+ }
830
+ async excelDeleteNamedRange(name) {
831
+ const escapedName = name.replace(/'/g, "''");
832
+ return this.executePowerShell(`
833
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
834
+ $workbook = $excel.ActiveWorkbook
835
+ $workbook.Names('${escapedName}').Delete()
836
+ @{ success = $true; message = "Named range '${escapedName}' deleted" } | ConvertTo-Json -Compress
837
+ `);
838
+ }
839
+ async excelCopyRange(range, sheet) {
840
+ const sheetScript = sheet ?
841
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
842
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
843
+ return this.executePowerShell(`
844
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
845
+ ${sheetScript}
846
+ $sheet.Range('${range}').Copy()
847
+ @{ success = $true; message = "Range ${range} copied to clipboard" } | ConvertTo-Json -Compress
848
+ `);
849
+ }
850
+ async excelPasteRange(destination, sheet) {
851
+ const sheetScript = sheet ?
852
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
853
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
854
+ return this.executePowerShell(`
855
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
856
+ ${sheetScript}
857
+ $sheet.Range('${destination}').Select()
858
+ $sheet.Paste()
859
+ @{ success = $true; message = "Pasted to ${destination}" } | ConvertTo-Json -Compress
860
+ `);
861
+ }
862
+ async excelClearRange(range, clearType = 'all', sheet) {
863
+ const sheetScript = sheet ?
864
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
865
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
866
+ const clearMethod = {
867
+ all: 'Clear()',
868
+ contents: 'ClearContents()',
869
+ formats: 'ClearFormats()',
870
+ comments: 'ClearComments()',
871
+ }[clearType];
872
+ return this.executePowerShell(`
873
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
874
+ ${sheetScript}
875
+ $sheet.Range('${range}').${clearMethod}
876
+ @{ success = $true; message = "Range ${range} cleared (${clearType})" } | ConvertTo-Json -Compress
877
+ `);
878
+ }
879
+ async excelHideColumn(column, sheet) {
880
+ const sheetScript = sheet ?
881
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
882
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
883
+ return this.executePowerShell(`
884
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
885
+ ${sheetScript}
886
+ $sheet.Columns('${column}').Hidden = $true
887
+ @{ success = $true; message = "Column ${column} hidden" } | ConvertTo-Json -Compress
888
+ `);
889
+ }
890
+ async excelShowColumn(column, sheet) {
891
+ const sheetScript = sheet ?
892
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
893
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
894
+ return this.executePowerShell(`
895
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
896
+ ${sheetScript}
897
+ $sheet.Columns('${column}').Hidden = $false
898
+ @{ success = $true; message = "Column ${column} shown" } | ConvertTo-Json -Compress
899
+ `);
900
+ }
901
+ async excelHideRow(row, sheet) {
902
+ const sheetScript = sheet ?
903
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
904
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
905
+ return this.executePowerShell(`
906
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
907
+ ${sheetScript}
908
+ $sheet.Rows(${row}).Hidden = $true
909
+ @{ success = $true; message = "Row ${row} hidden" } | ConvertTo-Json -Compress
910
+ `);
911
+ }
912
+ async excelShowRow(row, sheet) {
913
+ const sheetScript = sheet ?
914
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
915
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
916
+ return this.executePowerShell(`
917
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
918
+ ${sheetScript}
919
+ $sheet.Rows(${row}).Hidden = $false
920
+ @{ success = $true; message = "Row ${row} shown" } | ConvertTo-Json -Compress
921
+ `);
922
+ }
923
+ async excelAddImage(imagePath, cell, options) {
924
+ const windowsPath = this.toWindowsPath(imagePath).replace(/'/g, "''");
925
+ const sheetScript = options?.sheet ?
926
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${options.sheet.replace(/'/g, "''")}')` :
927
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
928
+ const sizeScript = [];
929
+ if (options?.width)
930
+ sizeScript.push(`$pic.Width = ${options.width}`);
931
+ if (options?.height)
932
+ sizeScript.push(`$pic.Height = ${options.height}`);
933
+ return this.executePowerShell(`
934
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
935
+ ${sheetScript}
936
+ $cell = $sheet.Range('${cell}')
937
+ $pic = $sheet.Shapes.AddPicture('${windowsPath}', 0, -1, $cell.Left, $cell.Top, -1, -1)
938
+ ${sizeScript.join('\n')}
939
+ @{ success = $true; message = "Image added at ${cell}" } | ConvertTo-Json -Compress
940
+ `);
941
+ }
942
+ async excelAddHyperlink(cell, url, displayText, sheet) {
943
+ const escapedUrl = url.replace(/'/g, "''");
944
+ const escapedText = displayText?.replace(/'/g, "''") || url;
945
+ const sheetScript = sheet ?
946
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
947
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
948
+ return this.executePowerShell(`
949
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
950
+ ${sheetScript}
951
+ $range = $sheet.Range('${cell}')
952
+ $sheet.Hyperlinks.Add($range, '${escapedUrl}', '', '', '${escapedText}')
953
+ @{ success = $true; message = "Hyperlink added to ${cell}" } | ConvertTo-Json -Compress
954
+ `);
955
+ }
956
+ async excelGetHyperlinks(sheet) {
957
+ const sheetScript = sheet ?
958
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
959
+ '$sheet = $workbook.ActiveSheet';
960
+ return this.executePowerShell(`
961
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
962
+ $workbook = $excel.ActiveWorkbook
963
+ ${sheetScript}
964
+ $links = @()
965
+ foreach ($hl in $sheet.Hyperlinks) {
966
+ $links += @{
967
+ cell = $hl.Range.Address($false, $false)
968
+ address = $hl.Address
969
+ subAddress = $hl.SubAddress
970
+ textToDisplay = $hl.TextToDisplay
971
+ screenTip = $hl.ScreenTip
972
+ }
973
+ }
974
+ @{ success = $true; hyperlinks = $links; count = $links.Count } | ConvertTo-Json -Compress -Depth 5
975
+ `);
976
+ }
977
+ async excelDeleteHyperlink(cell, sheet) {
978
+ const sheetScript = sheet ?
979
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
980
+ '$sheet = $workbook.ActiveSheet';
981
+ return this.executePowerShell(`
982
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
983
+ $workbook = $excel.ActiveWorkbook
984
+ ${sheetScript}
985
+ $range = $sheet.Range('${cell}')
986
+ $found = $false
987
+ foreach ($hl in $sheet.Hyperlinks) {
988
+ if ($hl.Range.Address -eq $range.Address) {
989
+ $hl.Delete()
990
+ $found = $true
991
+ break
992
+ }
993
+ }
994
+ if ($found) {
995
+ @{ success = $true; message = "Hyperlink deleted from ${cell}" } | ConvertTo-Json -Compress
996
+ } else {
997
+ @{ success = $false; error = "No hyperlink found in ${cell}" } | ConvertTo-Json -Compress
998
+ }
999
+ `);
1000
+ }
1001
+ async excelEditHyperlink(cell, newUrl, newDisplayText, sheet) {
1002
+ const sheetScript = sheet ?
1003
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1004
+ '$sheet = $workbook.ActiveSheet';
1005
+ const urlUpdate = newUrl ? `$hl.Address = '${newUrl.replace(/'/g, "''")}'` : '';
1006
+ const textUpdate = newDisplayText ? `$hl.TextToDisplay = '${newDisplayText.replace(/'/g, "''")}'` : '';
1007
+ return this.executePowerShell(`
1008
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1009
+ $workbook = $excel.ActiveWorkbook
1010
+ ${sheetScript}
1011
+ $range = $sheet.Range('${cell}')
1012
+ $found = $false
1013
+ foreach ($hl in $sheet.Hyperlinks) {
1014
+ if ($hl.Range.Address -eq $range.Address) {
1015
+ ${urlUpdate}
1016
+ ${textUpdate}
1017
+ $found = $true
1018
+ break
1019
+ }
1020
+ }
1021
+ if ($found) {
1022
+ @{ success = $true; message = "Hyperlink updated in ${cell}" } | ConvertTo-Json -Compress
1023
+ } else {
1024
+ @{ success = $false; error = "No hyperlink found in ${cell}" } | ConvertTo-Json -Compress
1025
+ }
1026
+ `);
1027
+ }
1028
+ async excelExportPDF(outputPath, sheet) {
1029
+ const windowsPath = this.toWindowsPath(outputPath).replace(/'/g, "''");
1030
+ const sheetScript = sheet ?
1031
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')
1032
+ $sheet.ExportAsFixedFormat(0, '${windowsPath}')` :
1033
+ `$excel.ActiveWorkbook.ExportAsFixedFormat(0, '${windowsPath}')`;
1034
+ return this.executePowerShell(`
1035
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1036
+ ${sheetScript}
1037
+ @{ success = $true; message = "Exported to PDF"; path = '${windowsPath}' } | ConvertTo-Json -Compress
1038
+ `);
1039
+ }
1040
+ async excelPrint(copies = 1, sheet) {
1041
+ const sheetScript = sheet ?
1042
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')
1043
+ $sheet.PrintOut(1, 9999, ${copies})` :
1044
+ `$excel.ActiveWorkbook.PrintOut(1, 9999, ${copies})`;
1045
+ return this.executePowerShell(`
1046
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1047
+ ${sheetScript}
1048
+ @{ success = $true; message = "Print job sent (${copies} copies)" } | ConvertTo-Json -Compress
1049
+ `);
1050
+ }
1051
+ async excelAddComment(cell, text, _author, sheet) {
1052
+ const escapedText = text.replace(/'/g, "''");
1053
+ const sheetScript = sheet ?
1054
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1055
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1056
+ return this.executePowerShell(`
1057
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1058
+ ${sheetScript}
1059
+ $cell = $sheet.Range('${cell}')
1060
+ if ($cell.Comment -ne $null) { $cell.Comment.Delete() }
1061
+ $comment = $cell.AddComment('${escapedText}')
1062
+ $comment.Visible = $false
1063
+ @{ success = $true; message = "Comment added to ${cell}" } | ConvertTo-Json -Compress
1064
+ `);
1065
+ }
1066
+ async excelGetComment(cell, sheet) {
1067
+ const sheetScript = sheet ?
1068
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1069
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1070
+ return this.executePowerShell(`
1071
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1072
+ ${sheetScript}
1073
+ $cell = $sheet.Range('${cell}')
1074
+ if ($cell.Comment -ne $null) {
1075
+ @{ success = $true; has_comment = $true; text = $cell.Comment.Text() } | ConvertTo-Json -Compress
1076
+ } else {
1077
+ @{ success = $true; has_comment = $false } | ConvertTo-Json -Compress
1078
+ }
1079
+ `);
1080
+ }
1081
+ async excelDeleteComment(cell, sheet) {
1082
+ const sheetScript = sheet ?
1083
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1084
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1085
+ return this.executePowerShell(`
1086
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1087
+ ${sheetScript}
1088
+ $cell = $sheet.Range('${cell}')
1089
+ if ($cell.Comment -ne $null) {
1090
+ $cell.Comment.Delete()
1091
+ @{ success = $true; message = "Comment deleted from ${cell}" } | ConvertTo-Json -Compress
1092
+ } else {
1093
+ @{ success = $false; error = "No comment found at ${cell}" } | ConvertTo-Json -Compress
1094
+ }
1095
+ `);
1096
+ }
1097
+ async excelProtectSheet(password, sheet) {
1098
+ const escapedPassword = password?.replace(/'/g, "''") || '';
1099
+ const sheetScript = sheet ?
1100
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1101
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1102
+ return this.executePowerShell(`
1103
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1104
+ ${sheetScript}
1105
+ $sheet.Protect('${escapedPassword}')
1106
+ @{ success = $true; message = "Sheet protected" } | ConvertTo-Json -Compress
1107
+ `);
1108
+ }
1109
+ async excelUnprotectSheet(password, sheet) {
1110
+ const escapedPassword = password?.replace(/'/g, "''") || '';
1111
+ const sheetScript = sheet ?
1112
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1113
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1114
+ return this.executePowerShell(`
1115
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1116
+ ${sheetScript}
1117
+ $sheet.Unprotect('${escapedPassword}')
1118
+ @{ success = $true; message = "Sheet unprotected" } | ConvertTo-Json -Compress
1119
+ `);
1120
+ }
1121
+ async excelUnmergeCells(range, sheet) {
1122
+ const sheetScript = sheet ?
1123
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1124
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1125
+ return this.executePowerShell(`
1126
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1127
+ ${sheetScript}
1128
+ $sheet.Range('${range}').UnMerge()
1129
+ @{ success = $true; message = "Cells unmerged: ${range}" } | ConvertTo-Json -Compress
1130
+ `);
1131
+ }
1132
+ async excelSelectSheet(name) {
1133
+ const escapedName = name.replace(/'/g, "''");
1134
+ return this.executePowerShell(`
1135
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1136
+ $excel.ActiveWorkbook.Worksheets('${escapedName}').Activate()
1137
+ @{ success = $true; message = "Sheet '${escapedName}' activated" } | ConvertTo-Json -Compress
1138
+ `);
1139
+ }
1140
+ async excelFindReplace(find, replace, options) {
1141
+ const escapedFind = find.replace(/'/g, "''");
1142
+ const escapedReplace = replace.replace(/'/g, "''");
1143
+ const sheetScript = options?.sheet ?
1144
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${options.sheet.replace(/'/g, "''")}')` :
1145
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1146
+ const rangeScript = options?.range ?
1147
+ `$range = $sheet.Range('${options.range}')` :
1148
+ '$range = $sheet.UsedRange';
1149
+ const matchCase = options?.matchCase ? '$true' : '$false';
1150
+ const lookAt = options?.matchEntireCell ? '1' : '2';
1151
+ return this.executePowerShell(`
1152
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1153
+ ${sheetScript}
1154
+ ${rangeScript}
1155
+ $replaced = $range.Replace('${escapedFind}', '${escapedReplace}', ${lookAt}, 1, ${matchCase})
1156
+ @{ success = $true; message = "Find and replace completed" } | ConvertTo-Json -Compress
1157
+ `);
1158
+ }
1159
+ async excelGroupRows(startRow, endRow, sheet) {
1160
+ const sheetScript = sheet ?
1161
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1162
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1163
+ return this.executePowerShell(`
1164
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1165
+ ${sheetScript}
1166
+ $sheet.Rows("${startRow}:${endRow}").Group()
1167
+ @{ success = $true; message = "Rows ${startRow}-${endRow} grouped" } | ConvertTo-Json -Compress
1168
+ `);
1169
+ }
1170
+ async excelUngroupRows(startRow, endRow, sheet) {
1171
+ const sheetScript = sheet ?
1172
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1173
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1174
+ return this.executePowerShell(`
1175
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1176
+ ${sheetScript}
1177
+ $sheet.Rows("${startRow}:${endRow}").Ungroup()
1178
+ @{ success = $true; message = "Rows ${startRow}-${endRow} ungrouped" } | ConvertTo-Json -Compress
1179
+ `);
1180
+ }
1181
+ async excelCreatePivotTable(sourceRange, destCell, tableName, sheet) {
1182
+ const escapedName = tableName?.replace(/'/g, "''") || `PivotTable${Date.now()}`;
1183
+ const sheetScript = sheet ?
1184
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1185
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1186
+ return this.executePowerShell(`
1187
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1188
+ $workbook = $excel.ActiveWorkbook
1189
+ ${sheetScript}
1190
+ $sourceRange = $sheet.Range('${sourceRange}')
1191
+ $destRange = $sheet.Range('${destCell}')
1192
+
1193
+ $pivotCache = $workbook.PivotCaches().Create(1, $sourceRange) # xlDatabase = 1
1194
+ $pivotTable = $pivotCache.CreatePivotTable($destRange, '${escapedName}')
1195
+
1196
+ @{ success = $true; message = "Pivot table created"; table_name = '${escapedName}' } | ConvertTo-Json -Compress
1197
+ `);
1198
+ }
1199
+ async excelAddPivotField(tableName, fieldName, orientation, aggregateFunction) {
1200
+ const escapedTableName = tableName.replace(/'/g, "''");
1201
+ const escapedFieldName = fieldName.replace(/'/g, "''");
1202
+ const orientationMap = {
1203
+ row: 1,
1204
+ column: 2,
1205
+ data: 4,
1206
+ page: 3,
1207
+ };
1208
+ const xlOrientation = orientationMap[orientation];
1209
+ const functionMap = {
1210
+ sum: -4157,
1211
+ count: -4112,
1212
+ average: -4106,
1213
+ max: -4136,
1214
+ min: -4139,
1215
+ };
1216
+ const xlFunction = aggregateFunction ? functionMap[aggregateFunction] : -4157;
1217
+ const functionScript = orientation === 'data' ? `$field.Function = ${xlFunction}` : '';
1218
+ return this.executePowerShell(`
1219
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1220
+ $workbook = $excel.ActiveWorkbook
1221
+ $pivotTable = $null
1222
+ foreach ($ws in $workbook.Worksheets) {
1223
+ foreach ($pt in $ws.PivotTables()) {
1224
+ if ($pt.Name -eq '${escapedTableName}') {
1225
+ $pivotTable = $pt
1226
+ break
1227
+ }
1228
+ }
1229
+ if ($pivotTable -ne $null) { break }
1230
+ }
1231
+
1232
+ if ($pivotTable -eq $null) {
1233
+ @{ success = $false; error = "Pivot table '${escapedTableName}' not found" } | ConvertTo-Json -Compress
1234
+ } else {
1235
+ $field = $pivotTable.PivotFields('${escapedFieldName}')
1236
+ $field.Orientation = ${xlOrientation}
1237
+ ${functionScript}
1238
+ @{ success = $true; message = "Field '${escapedFieldName}' added as ${orientation}" } | ConvertTo-Json -Compress
1239
+ }
1240
+ `);
1241
+ }
1242
+ async excelRefreshPivotTable(tableName) {
1243
+ const escapedTableName = tableName.replace(/'/g, "''");
1244
+ return this.executePowerShell(`
1245
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1246
+ $workbook = $excel.ActiveWorkbook
1247
+ $pivotTable = $null
1248
+ foreach ($ws in $workbook.Worksheets) {
1249
+ foreach ($pt in $ws.PivotTables()) {
1250
+ if ($pt.Name -eq '${escapedTableName}') {
1251
+ $pivotTable = $pt
1252
+ break
1253
+ }
1254
+ }
1255
+ if ($pivotTable -ne $null) { break }
1256
+ }
1257
+
1258
+ if ($pivotTable -eq $null) {
1259
+ @{ success = $false; error = "Pivot table '${escapedTableName}' not found" } | ConvertTo-Json -Compress
1260
+ } else {
1261
+ $pivotTable.RefreshTable()
1262
+ @{ success = $true; message = "Pivot table '${escapedTableName}' refreshed" } | ConvertTo-Json -Compress
1263
+ }
1264
+ `);
1265
+ }
1266
+ async excelInsertVlookup(cell, lookupValue, tableRange, colIndex, exactMatch = true, sheet) {
1267
+ const sheetScript = sheet ?
1268
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1269
+ '$sheet = $workbook.ActiveSheet';
1270
+ const matchType = exactMatch ? 'FALSE' : 'TRUE';
1271
+ const formula = `=VLOOKUP(${lookupValue},${tableRange},${colIndex},${matchType})`;
1272
+ return this.executePowerShell(`
1273
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1274
+ $workbook = $excel.ActiveWorkbook
1275
+ ${sheetScript}
1276
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1277
+ @{ success = $true; message = "VLOOKUP formula inserted in ${cell}" } | ConvertTo-Json -Compress
1278
+ `);
1279
+ }
1280
+ async excelInsertSumif(cell, range, criteria, sumRange, sheet) {
1281
+ const sheetScript = sheet ?
1282
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1283
+ '$sheet = $workbook.ActiveSheet';
1284
+ const formattedCriteria = formatFormulaCriteria(criteria);
1285
+ const formula = sumRange
1286
+ ? `=SUMIF(${range},${formattedCriteria},${sumRange})`
1287
+ : `=SUMIF(${range},${formattedCriteria})`;
1288
+ return this.executePowerShell(`
1289
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1290
+ $workbook = $excel.ActiveWorkbook
1291
+ ${sheetScript}
1292
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1293
+ @{ success = $true; message = "SUMIF formula inserted in ${cell}" } | ConvertTo-Json -Compress
1294
+ `);
1295
+ }
1296
+ async excelInsertCountif(cell, range, criteria, sheet) {
1297
+ const sheetScript = sheet ?
1298
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1299
+ '$sheet = $workbook.ActiveSheet';
1300
+ const formattedCriteria = formatFormulaCriteria(criteria);
1301
+ const formula = `=COUNTIF(${range},${formattedCriteria})`;
1302
+ return this.executePowerShell(`
1303
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1304
+ $workbook = $excel.ActiveWorkbook
1305
+ ${sheetScript}
1306
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1307
+ @{ success = $true; message = "COUNTIF formula inserted in ${cell}" } | ConvertTo-Json -Compress
1308
+ `);
1309
+ }
1310
+ async excelInsertIndexMatch(cell, returnRange, lookupRange, lookupValue, sheet) {
1311
+ const sheetScript = sheet ?
1312
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1313
+ '$sheet = $workbook.ActiveSheet';
1314
+ const formula = `=INDEX(${returnRange},MATCH(${lookupValue},${lookupRange},0))`;
1315
+ return this.executePowerShell(`
1316
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1317
+ $workbook = $excel.ActiveWorkbook
1318
+ ${sheetScript}
1319
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1320
+ @{ success = $true; message = "INDEX-MATCH formula inserted in ${cell}" } | ConvertTo-Json -Compress
1321
+ `);
1322
+ }
1323
+ async excelInsertAverageif(cell, range, criteria, avgRange, sheet) {
1324
+ const sheetScript = sheet ?
1325
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1326
+ '$sheet = $workbook.ActiveSheet';
1327
+ const formattedCriteria = formatFormulaCriteria(criteria);
1328
+ const formula = avgRange
1329
+ ? `=AVERAGEIF(${range},${formattedCriteria},${avgRange})`
1330
+ : `=AVERAGEIF(${range},${formattedCriteria})`;
1331
+ return this.executePowerShell(`
1332
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1333
+ $workbook = $excel.ActiveWorkbook
1334
+ ${sheetScript}
1335
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1336
+ @{ success = $true; message = "AVERAGEIF formula inserted in ${cell}" } | ConvertTo-Json -Compress
1337
+ `);
1338
+ }
1339
+ async excelInsertSumifs(cell, sumRange, criteriaRanges, criteria, sheet) {
1340
+ const sheetScript = sheet ?
1341
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1342
+ '$sheet = $workbook.ActiveSheet';
1343
+ const criteriaPairs = criteriaRanges.map((range, i) => {
1344
+ const formattedCriteria = formatFormulaCriteria(criteria[i] || '');
1345
+ return `${range},${formattedCriteria}`;
1346
+ }).join(',');
1347
+ const formula = `=SUMIFS(${sumRange},${criteriaPairs})`;
1348
+ return this.executePowerShell(`
1349
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1350
+ $workbook = $excel.ActiveWorkbook
1351
+ ${sheetScript}
1352
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1353
+ @{ success = $true; message = "SUMIFS formula inserted in ${cell}" } | ConvertTo-Json -Compress
1354
+ `);
1355
+ }
1356
+ async excelInsertCountifs(cell, criteriaRanges, criteria, sheet) {
1357
+ const sheetScript = sheet ?
1358
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1359
+ '$sheet = $workbook.ActiveSheet';
1360
+ const criteriaPairs = criteriaRanges.map((range, i) => {
1361
+ const formattedCriteria = formatFormulaCriteria(criteria[i] || '');
1362
+ return `${range},${formattedCriteria}`;
1363
+ }).join(',');
1364
+ const formula = `=COUNTIFS(${criteriaPairs})`;
1365
+ return this.executePowerShell(`
1366
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1367
+ $workbook = $excel.ActiveWorkbook
1368
+ ${sheetScript}
1369
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1370
+ @{ success = $true; message = "COUNTIFS formula inserted in ${cell}" } | ConvertTo-Json -Compress
1371
+ `);
1372
+ }
1373
+ async excelInsertXlookup(cell, lookupValue, lookupRange, returnRange, notFoundValue, matchMode, sheet) {
1374
+ const sheetScript = sheet ?
1375
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1376
+ '$sheet = $workbook.ActiveSheet';
1377
+ const matchModeMap = {
1378
+ exact: 0,
1379
+ exactOrNext: 1,
1380
+ exactOrPrev: -1,
1381
+ wildcard: 2,
1382
+ };
1383
+ const matchModeValue = matchMode ? matchModeMap[matchMode] : 0;
1384
+ let formula = `=XLOOKUP(${lookupValue},${lookupRange},${returnRange}`;
1385
+ if (notFoundValue !== undefined || matchMode) {
1386
+ if (notFoundValue !== undefined) {
1387
+ formula += `,"${notFoundValue.replace(/"/g, '""')}"`;
1388
+ }
1389
+ else {
1390
+ formula += ',';
1391
+ }
1392
+ if (matchMode || notFoundValue !== undefined) {
1393
+ formula += `,${matchModeValue}`;
1394
+ }
1395
+ }
1396
+ formula += ')';
1397
+ return this.executePowerShell(`
1398
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1399
+ $workbook = $excel.ActiveWorkbook
1400
+ ${sheetScript}
1401
+ $sheet.Range('${cell}').Formula = '${formula.replace(/'/g, "''")}'
1402
+ @{ success = $true; message = "XLOOKUP formula inserted in ${cell}" } | ConvertTo-Json -Compress
1403
+ `);
1404
+ }
1405
+ async excelUnmergeAndFill(range, sheet) {
1406
+ const sheetScript = sheet ?
1407
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1408
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1409
+ return this.executePowerShell(`
1410
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1411
+ ${sheetScript}
1412
+ $range = $sheet.Range('${range}')
1413
+ $filledCount = 0
1414
+ $processedAreas = @{}
1415
+
1416
+ # Find all merge areas in the range (check first cell of each row for efficiency)
1417
+ foreach ($cell in $range) {
1418
+ if ($cell.MergeCells) {
1419
+ $mergeArea = $cell.MergeArea
1420
+ $areaAddress = $mergeArea.Address
1421
+
1422
+ # Skip if already processed
1423
+ if (-not $processedAreas.ContainsKey($areaAddress)) {
1424
+ $processedAreas[$areaAddress] = $true
1425
+ $originalValue = $mergeArea.Cells(1, 1).Value2
1426
+ $cellCount = $mergeArea.Cells.Count
1427
+ $mergeArea.UnMerge()
1428
+
1429
+ # Fill all cells at once using Value assignment
1430
+ $mergeArea.Value2 = $originalValue
1431
+ $filledCount += $cellCount
1432
+ }
1433
+ }
1434
+ }
1435
+
1436
+ @{ success = $true; message = "Unmerged and filled ${range} ($($processedAreas.Count) merge areas)"; cells_filled = $filledCount; merge_areas = $processedAreas.Count } | ConvertTo-Json -Compress
1437
+ `);
1438
+ }
1439
+ async excelAddChartSeries(chartIndex, valuesRange, nameRange, sheet) {
1440
+ const sheetScript = sheet ?
1441
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1442
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1443
+ const nameScript = nameRange ? `$series.Name = $sheet.Range('${nameRange}').Value2` : '';
1444
+ return this.executePowerShell(`
1445
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1446
+ ${sheetScript}
1447
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1448
+ $chart = $chartObj.Chart
1449
+ $series = $chart.SeriesCollection().NewSeries()
1450
+ $series.Values = $sheet.Range('${valuesRange}')
1451
+ ${nameScript}
1452
+ @{ success = $true; message = "Series added to chart"; series_index = $chart.SeriesCollection().Count } | ConvertTo-Json -Compress
1453
+ `);
1454
+ }
1455
+ async excelEditChartSeries(chartIndex, seriesIndex, options, sheet) {
1456
+ const sheetScript = sheet ?
1457
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1458
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1459
+ const commands = [];
1460
+ if (options.valuesRange) {
1461
+ commands.push(`$series.Values = $sheet.Range('${options.valuesRange}')`);
1462
+ }
1463
+ if (options.nameRange) {
1464
+ commands.push(`$series.Name = $sheet.Range('${options.nameRange}').Value2`);
1465
+ }
1466
+ if (options.name) {
1467
+ commands.push(`$series.Name = '${options.name.replace(/'/g, "''")}'`);
1468
+ }
1469
+ return this.executePowerShell(`
1470
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1471
+ ${sheetScript}
1472
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1473
+ $chart = $chartObj.Chart
1474
+ $series = $chart.SeriesCollection(${seriesIndex})
1475
+ ${commands.join('\n')}
1476
+ @{ success = $true; message = "Series ${seriesIndex} updated" } | ConvertTo-Json -Compress
1477
+ `);
1478
+ }
1479
+ async excelDeleteChartSeries(chartIndex, seriesIndex, sheet) {
1480
+ const sheetScript = sheet ?
1481
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1482
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1483
+ return this.executePowerShell(`
1484
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1485
+ ${sheetScript}
1486
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1487
+ $chart = $chartObj.Chart
1488
+ $chart.SeriesCollection(${seriesIndex}).Delete()
1489
+ @{ success = $true; message = "Series ${seriesIndex} deleted from chart" } | ConvertTo-Json -Compress
1490
+ `);
1491
+ }
1492
+ async excelSetChartLegend(chartIndex, options, sheet) {
1493
+ const sheetScript = sheet ?
1494
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1495
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1496
+ const positionMap = {
1497
+ bottom: -4107,
1498
+ top: -4160,
1499
+ left: -4131,
1500
+ right: -4152,
1501
+ corner: 2,
1502
+ };
1503
+ let legendScript = '';
1504
+ if (options.show === false) {
1505
+ legendScript = '$chart.HasLegend = $false';
1506
+ }
1507
+ else {
1508
+ legendScript = '$chart.HasLegend = $true';
1509
+ if (options.position) {
1510
+ legendScript += `; $chart.Legend.Position = ${positionMap[options.position]}`;
1511
+ }
1512
+ }
1513
+ return this.executePowerShell(`
1514
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1515
+ ${sheetScript}
1516
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1517
+ $chart = $chartObj.Chart
1518
+ ${legendScript}
1519
+ @{ success = $true; message = "Chart legend updated" } | ConvertTo-Json -Compress
1520
+ `);
1521
+ }
1522
+ async excelSetChartDataLabels(chartIndex, options, sheet) {
1523
+ const sheetScript = sheet ?
1524
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1525
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1526
+ const labelScript = options.show === false
1527
+ ? 'foreach ($s in $chart.SeriesCollection()) { $s.HasDataLabels = $false }'
1528
+ : `foreach ($s in $chart.SeriesCollection()) {
1529
+ $s.HasDataLabels = $true
1530
+ $s.DataLabels.ShowValue = ${options.showValue !== false ? '$true' : '$false'}
1531
+ $s.DataLabels.ShowCategoryName = ${options.showCategory ? '$true' : '$false'}
1532
+ $s.DataLabels.ShowPercentage = ${options.showPercent ? '$true' : '$false'}
1533
+ }`;
1534
+ return this.executePowerShell(`
1535
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1536
+ ${sheetScript}
1537
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1538
+ $chart = $chartObj.Chart
1539
+ ${labelScript}
1540
+ @{ success = $true; message = "Chart data labels updated" } | ConvertTo-Json -Compress
1541
+ `);
1542
+ }
1543
+ async excelSetChartAxis(chartIndex, axisType, options, sheet) {
1544
+ const sheetScript = sheet ?
1545
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1546
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1547
+ const axisNum = axisType === 'x' ? 1 : 2;
1548
+ let axisScript = `$axis = $chart.Axes(${axisNum})`;
1549
+ if (options.title !== undefined) {
1550
+ axisScript += `
1551
+ $axis.HasTitle = $true
1552
+ $axis.AxisTitle.Text = '${options.title.replace(/'/g, "''")}'`;
1553
+ }
1554
+ if (options.min !== undefined) {
1555
+ axisScript += `
1556
+ $axis.MinimumScale = ${options.min}`;
1557
+ }
1558
+ if (options.max !== undefined) {
1559
+ axisScript += `
1560
+ $axis.MaximumScale = ${options.max}`;
1561
+ }
1562
+ if (options.majorUnit !== undefined) {
1563
+ axisScript += `
1564
+ $axis.MajorUnit = ${options.majorUnit}`;
1565
+ }
1566
+ return this.executePowerShell(`
1567
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1568
+ ${sheetScript}
1569
+ $chartObj = $sheet.ChartObjects(${chartIndex})
1570
+ $chart = $chartObj.Chart
1571
+ ${axisScript}
1572
+ @{ success = $true; message = "Chart ${axisType}-axis updated" } | ConvertTo-Json -Compress
1573
+ `);
1574
+ }
1575
+ async excelLockCells(range, lock = true, sheet) {
1576
+ const sheetScript = sheet ?
1577
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1578
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1579
+ const lockValue = lock ? '$true' : '$false';
1580
+ return this.executePowerShell(`
1581
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1582
+ ${sheetScript}
1583
+ $sheet.Range('${range}').Locked = ${lockValue}
1584
+ @{ success = $true; message = "Cells ${range} ${lock ? 'locked' : 'unlocked'}" } | ConvertTo-Json -Compress
1585
+ `);
1586
+ }
1587
+ async excelGetUsedRange(sheet) {
1588
+ const sheetScript = sheet ?
1589
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1590
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1591
+ return this.executePowerShell(`
1592
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1593
+ ${sheetScript}
1594
+ $usedRange = $sheet.UsedRange
1595
+ $address = $usedRange.Address
1596
+ $rows = $usedRange.Rows.Count
1597
+ $cols = $usedRange.Columns.Count
1598
+ $firstRow = $usedRange.Row
1599
+ $firstCol = $usedRange.Column
1600
+ @{
1601
+ success = $true
1602
+ range = $address
1603
+ rows = $rows
1604
+ columns = $cols
1605
+ first_row = $firstRow
1606
+ first_column = $firstCol
1607
+ } | ConvertTo-Json -Compress
1608
+ `);
1609
+ }
1610
+ async excelAutofitRange(range, fitColumns = true, fitRows = false, sheet) {
1611
+ const sheetScript = sheet ?
1612
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1613
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1614
+ const fitScript = [];
1615
+ if (fitColumns)
1616
+ fitScript.push('$range.Columns.AutoFit() | Out-Null');
1617
+ if (fitRows)
1618
+ fitScript.push('$range.Rows.AutoFit() | Out-Null');
1619
+ return this.executePowerShell(`
1620
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1621
+ ${sheetScript}
1622
+ $range = $sheet.Range('${range}')
1623
+ ${fitScript.join('\n')}
1624
+ @{ success = $true; message = "Autofit applied to ${range}" } | ConvertTo-Json -Compress
1625
+ `);
1626
+ }
1627
+ async excelRemoveDuplicates(range, columns, hasHeader = true, sheet) {
1628
+ const sheetScript = sheet ?
1629
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1630
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1631
+ const header = hasHeader ? 1 : 2;
1632
+ const columnsScript = columns && columns.length > 0
1633
+ ? `$columns = @(${columns.join(',')})`
1634
+ : `$columns = @(1..$range.Columns.Count)`;
1635
+ return this.executePowerShell(`
1636
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1637
+ ${sheetScript}
1638
+ $range = $sheet.Range('${range}')
1639
+ $beforeCount = $range.Rows.Count
1640
+ ${columnsScript}
1641
+ $range.RemoveDuplicates($columns, ${header})
1642
+ $afterCount = $sheet.Range('${range}').Rows.Count
1643
+ $removed = $beforeCount - $afterCount
1644
+ @{ success = $true; message = "$removed duplicate rows removed"; rows_removed = $removed } | ConvertTo-Json -Compress
1645
+ `);
1646
+ }
1647
+ async excelGetCharts(sheet) {
1648
+ const sheetScript = sheet ?
1649
+ `$sheet = $excel.ActiveWorkbook.Worksheets('${sheet.replace(/'/g, "''")}')` :
1650
+ '$sheet = $excel.ActiveWorkbook.ActiveSheet';
1651
+ return this.executePowerShell(`
1652
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1653
+ ${sheetScript}
1654
+ $charts = @()
1655
+ $index = 1
1656
+ foreach ($chartObj in $sheet.ChartObjects()) {
1657
+ $chart = $chartObj.Chart
1658
+ $charts += @{
1659
+ index = $index
1660
+ name = $chartObj.Name
1661
+ chart_type = $chart.ChartType
1662
+ has_title = $chart.HasTitle
1663
+ title = if ($chart.HasTitle) { $chart.ChartTitle.Text } else { $null }
1664
+ left = $chartObj.Left
1665
+ top = $chartObj.Top
1666
+ width = $chartObj.Width
1667
+ height = $chartObj.Height
1668
+ series_count = $chart.SeriesCollection().Count
1669
+ }
1670
+ $index++
1671
+ }
1672
+ @{ success = $true; charts = $charts; count = $charts.Count } | ConvertTo-Json -Compress -Depth 5
1673
+ `);
1674
+ }
1675
+ async excelCreateTable(range, tableName, hasHeaders = true, sheet) {
1676
+ const sheetScript = sheet ?
1677
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1678
+ '$sheet = $workbook.ActiveSheet';
1679
+ const xlSrcRange = 1;
1680
+ const xlYes = 1;
1681
+ const xlNo = 2;
1682
+ const headerOption = hasHeaders ? xlYes : xlNo;
1683
+ return this.executePowerShell(`
1684
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1685
+ $workbook = $excel.ActiveWorkbook
1686
+ ${sheetScript}
1687
+ $range = $sheet.Range('${range}')
1688
+ $table = $sheet.ListObjects.Add(${xlSrcRange}, $range, $null, ${headerOption})
1689
+ $table.Name = '${tableName.replace(/'/g, "''")}'
1690
+ $table.TableStyle = 'TableStyleMedium2'
1691
+ @{ success = $true; message = "Table '${tableName}' created"; table_name = $table.Name; range = '${range}' } | ConvertTo-Json -Compress
1692
+ `);
1693
+ }
1694
+ async excelDeleteTable(tableName, sheet) {
1695
+ const sheetScript = sheet ?
1696
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1697
+ '$sheet = $workbook.ActiveSheet';
1698
+ return this.executePowerShell(`
1699
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1700
+ $workbook = $excel.ActiveWorkbook
1701
+ ${sheetScript}
1702
+ $table = $sheet.ListObjects('${tableName.replace(/'/g, "''")}')
1703
+ $table.Delete()
1704
+ @{ success = $true; message = "Table '${tableName}' deleted" } | ConvertTo-Json -Compress
1705
+ `);
1706
+ }
1707
+ async excelGetTables(sheet) {
1708
+ const sheetScript = sheet ?
1709
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1710
+ '$sheet = $workbook.ActiveSheet';
1711
+ return this.executePowerShell(`
1712
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1713
+ $workbook = $excel.ActiveWorkbook
1714
+ ${sheetScript}
1715
+ $tables = @()
1716
+ foreach ($table in $sheet.ListObjects) {
1717
+ $tables += @{
1718
+ name = $table.Name
1719
+ range = $table.Range.Address()
1720
+ row_count = $table.ListRows.Count
1721
+ column_count = $table.ListColumns.Count
1722
+ has_headers = $table.ShowHeaders
1723
+ style = $table.TableStyle.Name
1724
+ }
1725
+ }
1726
+ @{ success = $true; tables = $tables; count = $tables.Count } | ConvertTo-Json -Compress -Depth 5
1727
+ `);
1728
+ }
1729
+ async excelAddTableColumn(tableName, columnName, formula, sheet) {
1730
+ const sheetScript = sheet ?
1731
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1732
+ '$sheet = $workbook.ActiveSheet';
1733
+ const formulaScript = formula
1734
+ ? `$newCol.DataBodyRange.Formula = '${formula.replace(/'/g, "''")}'`
1735
+ : '';
1736
+ return this.executePowerShell(`
1737
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1738
+ $workbook = $excel.ActiveWorkbook
1739
+ ${sheetScript}
1740
+ $table = $sheet.ListObjects('${tableName.replace(/'/g, "''")}')
1741
+ $newCol = $table.ListColumns.Add()
1742
+ $newCol.Name = '${columnName.replace(/'/g, "''")}'
1743
+ ${formulaScript}
1744
+ @{ success = $true; message = "Column '${columnName}' added to table '${tableName}'"; column_index = $newCol.Index } | ConvertTo-Json -Compress
1745
+ `);
1746
+ }
1747
+ async excelSetPageSetup(options, sheet) {
1748
+ const sheetScript = sheet ?
1749
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1750
+ '$sheet = $workbook.ActiveSheet';
1751
+ const orientationMap = {
1752
+ portrait: 1,
1753
+ landscape: 2,
1754
+ };
1755
+ const paperSizeMap = {
1756
+ letter: 1,
1757
+ legal: 5,
1758
+ a4: 9,
1759
+ a3: 8,
1760
+ };
1761
+ const commands = [];
1762
+ if (options.orientation) {
1763
+ commands.push(`$ps.Orientation = ${orientationMap[options.orientation]}`);
1764
+ }
1765
+ if (options.paperSize) {
1766
+ commands.push(`$ps.PaperSize = ${paperSizeMap[options.paperSize]}`);
1767
+ }
1768
+ if (options.margins) {
1769
+ if (options.margins.top !== undefined)
1770
+ commands.push(`$ps.TopMargin = $excel.InchesToPoints(${options.margins.top})`);
1771
+ if (options.margins.bottom !== undefined)
1772
+ commands.push(`$ps.BottomMargin = $excel.InchesToPoints(${options.margins.bottom})`);
1773
+ if (options.margins.left !== undefined)
1774
+ commands.push(`$ps.LeftMargin = $excel.InchesToPoints(${options.margins.left})`);
1775
+ if (options.margins.right !== undefined)
1776
+ commands.push(`$ps.RightMargin = $excel.InchesToPoints(${options.margins.right})`);
1777
+ }
1778
+ if (options.fitToPage) {
1779
+ commands.push('$ps.Zoom = $false');
1780
+ commands.push(`$ps.FitToPagesWide = ${options.fitToWidth ?? 1}`);
1781
+ commands.push(`$ps.FitToPagesTall = ${options.fitToHeight ?? 1}`);
1782
+ }
1783
+ return this.executePowerShell(`
1784
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1785
+ $workbook = $excel.ActiveWorkbook
1786
+ ${sheetScript}
1787
+ $ps = $sheet.PageSetup
1788
+ ${commands.join('\n')}
1789
+ @{ success = $true; message = "Page setup configured" } | ConvertTo-Json -Compress
1790
+ `);
1791
+ }
1792
+ async excelSetPrintArea(range, sheet) {
1793
+ const sheetScript = sheet ?
1794
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1795
+ '$sheet = $workbook.ActiveSheet';
1796
+ return this.executePowerShell(`
1797
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1798
+ $workbook = $excel.ActiveWorkbook
1799
+ ${sheetScript}
1800
+ $sheet.PageSetup.PrintArea = '${range}'
1801
+ @{ success = $true; message = "Print area set to '${range}'" } | ConvertTo-Json -Compress
1802
+ `);
1803
+ }
1804
+ async excelSetPrintTitles(rowsToRepeat, columnsToRepeat, sheet) {
1805
+ const sheetScript = sheet ?
1806
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1807
+ '$sheet = $workbook.ActiveSheet';
1808
+ const commands = [];
1809
+ if (rowsToRepeat) {
1810
+ commands.push(`$sheet.PageSetup.PrintTitleRows = '${rowsToRepeat}'`);
1811
+ }
1812
+ if (columnsToRepeat) {
1813
+ commands.push(`$sheet.PageSetup.PrintTitleColumns = '${columnsToRepeat}'`);
1814
+ }
1815
+ return this.executePowerShell(`
1816
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1817
+ $workbook = $excel.ActiveWorkbook
1818
+ ${sheetScript}
1819
+ ${commands.join('\n')}
1820
+ @{ success = $true; message = "Print titles configured"; rows = '${rowsToRepeat || ''}'; columns = '${columnsToRepeat || ''}' } | ConvertTo-Json -Compress
1821
+ `);
1822
+ }
1823
+ async excelInsertArrayFormula(range, formula, sheet) {
1824
+ const sheetScript = sheet ?
1825
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1826
+ '$sheet = $workbook.ActiveSheet';
1827
+ return this.executePowerShell(`
1828
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1829
+ $workbook = $excel.ActiveWorkbook
1830
+ ${sheetScript}
1831
+ $range = $sheet.Range('${range}')
1832
+ $range.FormulaArray = '${formula.replace(/'/g, "''")}'
1833
+ @{ success = $true; message = "Array formula inserted in '${range}'" } | ConvertTo-Json -Compress
1834
+ `);
1835
+ }
1836
+ async excelTranspose(sourceRange, destCell, sheet) {
1837
+ const sheetScript = sheet ?
1838
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1839
+ '$sheet = $workbook.ActiveSheet';
1840
+ return this.executePowerShell(`
1841
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1842
+ $workbook = $excel.ActiveWorkbook
1843
+ ${sheetScript}
1844
+ $srcRange = $sheet.Range('${sourceRange}')
1845
+ $values = $srcRange.Value2
1846
+ $transposed = $excel.WorksheetFunction.Transpose($values)
1847
+ $rows = $srcRange.Columns.Count
1848
+ $cols = $srcRange.Rows.Count
1849
+ $destStart = $sheet.Range('${destCell}')
1850
+ $destEnd = $sheet.Cells($destStart.Row + $rows - 1, $destStart.Column + $cols - 1)
1851
+ $destRange = $sheet.Range($destStart, $destEnd)
1852
+ $destRange.Value = $transposed
1853
+ @{ success = $true; message = "Transposed '${sourceRange}' to '${destCell}'"; new_size = "$rows x $cols" } | ConvertTo-Json -Compress
1854
+ `);
1855
+ }
1856
+ async excelTextToColumns(range, delimiter, destCell, sheet) {
1857
+ const sheetScript = sheet ?
1858
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1859
+ '$sheet = $workbook.ActiveSheet';
1860
+ const delimiterMap = {
1861
+ comma: '$true, $false, $false, $false, $false',
1862
+ tab: '$false, $false, $false, $true, $false',
1863
+ semicolon: '$false, $true, $false, $false, $false',
1864
+ space: '$false, $false, $false, $false, $true',
1865
+ };
1866
+ const delimiterArgs = delimiterMap[delimiter] || '$false, $false, $false, $false, $false';
1867
+ const otherDelim = delimiterMap[delimiter] ? '' : `, $false, '${delimiter}'`;
1868
+ const destScript = destCell ? `$sheet.Range('${destCell}')` : '$srcRange';
1869
+ return this.executePowerShell(`
1870
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1871
+ $workbook = $excel.ActiveWorkbook
1872
+ ${sheetScript}
1873
+ $srcRange = $sheet.Range('${range}')
1874
+ $srcRange.TextToColumns(${destScript}, 1, 1, $false, ${delimiterArgs}${otherDelim})
1875
+ @{ success = $true; message = "Text to columns applied to '${range}'" } | ConvertTo-Json -Compress
1876
+ `);
1877
+ }
1878
+ async excelHideSheet(sheetName) {
1879
+ return this.executePowerShell(`
1880
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1881
+ $workbook = $excel.ActiveWorkbook
1882
+ $sheet = $workbook.Sheets('${sheetName.replace(/'/g, "''")}')
1883
+ $sheet.Visible = 0 # xlSheetHidden
1884
+ @{ success = $true; message = "Sheet '${sheetName}' hidden" } | ConvertTo-Json -Compress
1885
+ `);
1886
+ }
1887
+ async excelShowSheet(sheetName) {
1888
+ return this.executePowerShell(`
1889
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1890
+ $workbook = $excel.ActiveWorkbook
1891
+ $sheet = $workbook.Sheets('${sheetName.replace(/'/g, "''")}')
1892
+ $sheet.Visible = -1 # xlSheetVisible
1893
+ @{ success = $true; message = "Sheet '${sheetName}' shown" } | ConvertTo-Json -Compress
1894
+ `);
1895
+ }
1896
+ async excelSetTabColor(sheetName, color) {
1897
+ const hexToRgb = (hex) => {
1898
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1899
+ if (!result || !result[1] || !result[2] || !result[3])
1900
+ return null;
1901
+ return {
1902
+ r: parseInt(result[1], 16),
1903
+ g: parseInt(result[2], 16),
1904
+ b: parseInt(result[3], 16)
1905
+ };
1906
+ };
1907
+ const rgb = hexToRgb(color);
1908
+ if (!rgb) {
1909
+ return { success: false, error: `Invalid hex color: ${color}` };
1910
+ }
1911
+ return this.executePowerShell(`
1912
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1913
+ $workbook = $excel.ActiveWorkbook
1914
+ $sheet = $workbook.Sheets('${sheetName.replace(/'/g, "''")}')
1915
+ $sheet.Tab.Color = [System.Drawing.ColorTranslator]::ToOle([System.Drawing.Color]::FromArgb(${rgb.r}, ${rgb.g}, ${rgb.b}))
1916
+ @{ success = $true; message = "Tab color set for '${sheetName}'" } | ConvertTo-Json -Compress
1917
+ `);
1918
+ }
1919
+ async excelSetZoom(zoomLevel, sheet) {
1920
+ if (zoomLevel < 10 || zoomLevel > 400) {
1921
+ return { success: false, error: `Invalid zoom level: ${zoomLevel}. Must be between 10 and 400.` };
1922
+ }
1923
+ const sheetScript = sheet ?
1924
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}'); $sheet.Activate()` :
1925
+ '';
1926
+ return this.executePowerShell(`
1927
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1928
+ $workbook = $excel.ActiveWorkbook
1929
+ ${sheetScript}
1930
+ $excel.ActiveWindow.Zoom = ${zoomLevel}
1931
+ @{ success = $true; message = "Zoom set to ${zoomLevel}%" } | ConvertTo-Json -Compress
1932
+ `);
1933
+ }
1934
+ async excelSetGridlines(show, sheet) {
1935
+ const sheetScript = sheet ?
1936
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}'); $sheet.Activate()` :
1937
+ '';
1938
+ return this.executePowerShell(`
1939
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1940
+ $workbook = $excel.ActiveWorkbook
1941
+ ${sheetScript}
1942
+ $excel.ActiveWindow.DisplayGridlines = ${show ? '$true' : '$false'}
1943
+ @{ success = $true; message = "Gridlines ${show ? 'shown' : 'hidden'}" } | ConvertTo-Json -Compress
1944
+ `);
1945
+ }
1946
+ async excelSetViewMode(mode, sheet) {
1947
+ const sheetScript = sheet ?
1948
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}'); $sheet.Activate()` :
1949
+ '';
1950
+ const modeMap = {
1951
+ normal: 1,
1952
+ pageBreak: 2,
1953
+ pageLayout: 3,
1954
+ };
1955
+ return this.executePowerShell(`
1956
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1957
+ $workbook = $excel.ActiveWorkbook
1958
+ ${sheetScript}
1959
+ $excel.ActiveWindow.View = ${modeMap[mode]}
1960
+ @{ success = $true; message = "View mode set to '${mode}'" } | ConvertTo-Json -Compress
1961
+ `);
1962
+ }
1963
+ async excelExportCsv(filePath, sheet) {
1964
+ const windowsPath = this.toWindowsPath(filePath).replace(/'/g, "''");
1965
+ const sheetScript = sheet ?
1966
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1967
+ '$sheet = $workbook.ActiveSheet';
1968
+ return this.executePowerShell(`
1969
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1970
+ $workbook = $excel.ActiveWorkbook
1971
+ ${sheetScript}
1972
+ $tempWorkbook = $excel.Workbooks.Add()
1973
+ $sheet.Copy($tempWorkbook.Sheets(1))
1974
+ $tempWorkbook.Sheets(1).Delete()
1975
+ $tempWorkbook.SaveAs('${windowsPath}', 6) # xlCSV = 6
1976
+ $tempWorkbook.Close($false)
1977
+ @{ success = $true; message = "Exported to CSV"; path = '${windowsPath}' } | ConvertTo-Json -Compress
1978
+ `);
1979
+ }
1980
+ async excelExportJson(range, filePath, sheet) {
1981
+ const windowsPath = this.toWindowsPath(filePath).replace(/'/g, "''");
1982
+ const sheetScript = sheet ?
1983
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
1984
+ '$sheet = $workbook.ActiveSheet';
1985
+ return this.executePowerShell(`
1986
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
1987
+ $workbook = $excel.ActiveWorkbook
1988
+ ${sheetScript}
1989
+ $range = $sheet.Range('${range}')
1990
+ $values = $range.Value2
1991
+ $rows = $range.Rows.Count
1992
+ $cols = $range.Columns.Count
1993
+
1994
+ # Get headers from first row
1995
+ $headers = @()
1996
+ for ($c = 1; $c -le $cols; $c++) {
1997
+ $headers += $values[1, $c]
1998
+ }
1999
+
2000
+ # Build JSON array
2001
+ $jsonArray = @()
2002
+ for ($r = 2; $r -le $rows; $r++) {
2003
+ $obj = @{}
2004
+ for ($c = 1; $c -le $cols; $c++) {
2005
+ $obj[$headers[$c-1]] = $values[$r, $c]
2006
+ }
2007
+ $jsonArray += $obj
2008
+ }
2009
+
2010
+ $json = $jsonArray | ConvertTo-Json -Depth 10
2011
+ [System.IO.File]::WriteAllText('${windowsPath}', $json, [System.Text.Encoding]::UTF8)
2012
+ @{ success = $true; message = "Exported to JSON"; path = '${windowsPath}'; rows = ($rows - 1) } | ConvertTo-Json -Compress
2013
+ `);
2014
+ }
2015
+ async excelImportCsv(filePath, destCell, delimiter = ',', sheet) {
2016
+ const windowsPath = this.toWindowsPath(filePath).replace(/'/g, "''");
2017
+ const sheetScript = sheet ?
2018
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2019
+ '$sheet = $workbook.ActiveSheet';
2020
+ const textQualifier = 1;
2021
+ return this.executePowerShell(`
2022
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2023
+ $workbook = $excel.ActiveWorkbook
2024
+ ${sheetScript}
2025
+ $destRange = $sheet.Range('${destCell}')
2026
+ $qt = $sheet.QueryTables.Add("TEXT;${windowsPath}", $destRange)
2027
+ $qt.TextFileParseType = 1 # xlDelimited
2028
+ $qt.TextFileCommaDelimiter = ${delimiter === ',' ? '$true' : '$false'}
2029
+ $qt.TextFileTabDelimiter = ${delimiter === '\t' ? '$true' : '$false'}
2030
+ $qt.TextFileSemicolonDelimiter = ${delimiter === ';' ? '$true' : '$false'}
2031
+ $qt.TextFileSpaceDelimiter = ${delimiter === ' ' ? '$true' : '$false'}
2032
+ $qt.TextFileTextQualifier = ${textQualifier}
2033
+ $qt.Refresh($false)
2034
+ $qt.Delete()
2035
+ @{ success = $true; message = "CSV imported to ${destCell}"; source = '${windowsPath}' } | ConvertTo-Json -Compress
2036
+ `);
2037
+ }
2038
+ async excelRemoveImage(imageName, sheet) {
2039
+ const sheetScript = sheet ?
2040
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2041
+ '$sheet = $workbook.ActiveSheet';
2042
+ return this.executePowerShell(`
2043
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2044
+ $workbook = $excel.ActiveWorkbook
2045
+ ${sheetScript}
2046
+ $shape = $sheet.Shapes('${imageName.replace(/'/g, "''")}')
2047
+ $shape.Delete()
2048
+ @{ success = $true; message = "Image '${imageName}' removed" } | ConvertTo-Json -Compress
2049
+ `);
2050
+ }
2051
+ async excelGetImages(sheet) {
2052
+ const sheetScript = sheet ?
2053
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2054
+ '$sheet = $workbook.ActiveSheet';
2055
+ return this.executePowerShell(`
2056
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2057
+ $workbook = $excel.ActiveWorkbook
2058
+ ${sheetScript}
2059
+ $images = @()
2060
+ foreach ($shape in $sheet.Shapes) {
2061
+ if ($shape.Type -eq 13) { # msoPicture
2062
+ $images += @{
2063
+ name = $shape.Name
2064
+ left = $shape.Left
2065
+ top = $shape.Top
2066
+ width = $shape.Width
2067
+ height = $shape.Height
2068
+ }
2069
+ }
2070
+ }
2071
+ @{ success = $true; images = $images; count = $images.Count } | ConvertTo-Json -Compress -Depth 5
2072
+ `);
2073
+ }
2074
+ async excelEditComment(cell, newText, sheet) {
2075
+ const sheetScript = sheet ?
2076
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2077
+ '$sheet = $workbook.ActiveSheet';
2078
+ const hasKorean = /[가-힣ㄱ-ㅎㅏ-ㅣ]/.test(newText);
2079
+ return this.executePowerShell(`
2080
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2081
+ $workbook = $excel.ActiveWorkbook
2082
+ ${sheetScript}
2083
+ $cell = $sheet.Range('${cell}')
2084
+ if ($cell.Comment -eq $null) {
2085
+ @{ success = $false; error = "No comment exists in cell ${cell}" } | ConvertTo-Json -Compress
2086
+ } else {
2087
+ $cell.Comment.Text('${newText.replace(/'/g, "''")}')
2088
+ ${hasKorean ? "$cell.Comment.Shape.TextFrame.Characters().Font.Name = 'Malgun Gothic'" : ''}
2089
+ @{ success = $true; message = "Comment updated in ${cell}" } | ConvertTo-Json -Compress
2090
+ }
2091
+ `);
2092
+ }
2093
+ async excelDeletePivotField(tableName, fieldName, sheet) {
2094
+ const sheetScript = sheet ?
2095
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2096
+ '$sheet = $workbook.ActiveSheet';
2097
+ return this.executePowerShell(`
2098
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2099
+ $workbook = $excel.ActiveWorkbook
2100
+ ${sheetScript}
2101
+ $pivotTable = $sheet.PivotTables('${tableName.replace(/'/g, "''")}')
2102
+ $field = $pivotTable.PivotFields('${fieldName.replace(/'/g, "''")}')
2103
+ $field.Orientation = 0 # xlHidden
2104
+ @{ success = $true; message = "Field '${fieldName}' removed from pivot table '${tableName}'" } | ConvertTo-Json -Compress
2105
+ `);
2106
+ }
2107
+ async excelSetCalculationMode(mode) {
2108
+ const modeMap = {
2109
+ automatic: -4105,
2110
+ manual: -4135,
2111
+ semiautomatic: 2,
2112
+ };
2113
+ return this.executePowerShell(`
2114
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2115
+ $excel.Calculation = ${modeMap[mode]}
2116
+ @{ success = $true; message = "Calculation mode set to '${mode}'" } | ConvertTo-Json -Compress
2117
+ `);
2118
+ }
2119
+ async excelRecalculate(scope, range, sheet) {
2120
+ const sheetScript = sheet ?
2121
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2122
+ '$sheet = $workbook.ActiveSheet';
2123
+ let calcScript = '';
2124
+ switch (scope) {
2125
+ case 'workbook':
2126
+ calcScript = '$excel.CalculateFull()';
2127
+ break;
2128
+ case 'sheet':
2129
+ calcScript = `${sheetScript}\n$sheet.Calculate()`;
2130
+ break;
2131
+ case 'range':
2132
+ calcScript = `${sheetScript}\n$sheet.Range('${range}').Calculate()`;
2133
+ break;
2134
+ }
2135
+ return this.executePowerShell(`
2136
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2137
+ $workbook = $excel.ActiveWorkbook
2138
+ ${calcScript}
2139
+ @{ success = $true; message = "Recalculated ${scope}" } | ConvertTo-Json -Compress
2140
+ `);
2141
+ }
2142
+ async excelTracePrecedents(cell, sheet) {
2143
+ const sheetScript = sheet ?
2144
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2145
+ '$sheet = $workbook.ActiveSheet';
2146
+ return this.executePowerShell(`
2147
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2148
+ $workbook = $excel.ActiveWorkbook
2149
+ ${sheetScript}
2150
+ $cell = $sheet.Range('${cell}')
2151
+ $cell.ShowPrecedents()
2152
+ @{ success = $true; message = "Showing precedents for ${cell}" } | ConvertTo-Json -Compress
2153
+ `);
2154
+ }
2155
+ async excelTraceDependents(cell, sheet) {
2156
+ const sheetScript = sheet ?
2157
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2158
+ '$sheet = $workbook.ActiveSheet';
2159
+ return this.executePowerShell(`
2160
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2161
+ $workbook = $excel.ActiveWorkbook
2162
+ ${sheetScript}
2163
+ $cell = $sheet.Range('${cell}')
2164
+ $cell.ShowDependents()
2165
+ @{ success = $true; message = "Showing dependents for ${cell}" } | ConvertTo-Json -Compress
2166
+ `);
2167
+ }
2168
+ async excelClearArrows() {
2169
+ return this.executePowerShell(`
2170
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2171
+ $workbook = $excel.ActiveWorkbook
2172
+ $workbook.ActiveSheet.ClearArrows()
2173
+ @{ success = $true; message = "Cleared all arrows" } | ConvertTo-Json -Compress
2174
+ `);
2175
+ }
2176
+ async excelGroupColumns(startCol, endCol, sheet) {
2177
+ const sheetScript = sheet ?
2178
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2179
+ '$sheet = $workbook.ActiveSheet';
2180
+ return this.executePowerShell(`
2181
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2182
+ $workbook = $excel.ActiveWorkbook
2183
+ ${sheetScript}
2184
+ $range = $sheet.Columns("${startCol}:${endCol}")
2185
+ $range.Group()
2186
+ @{ success = $true; message = "Grouped columns ${startCol} to ${endCol}" } | ConvertTo-Json -Compress
2187
+ `);
2188
+ }
2189
+ async excelUngroupColumns(startCol, endCol, sheet) {
2190
+ const sheetScript = sheet ?
2191
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2192
+ '$sheet = $workbook.ActiveSheet';
2193
+ return this.executePowerShell(`
2194
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2195
+ $workbook = $excel.ActiveWorkbook
2196
+ ${sheetScript}
2197
+ $range = $sheet.Columns("${startCol}:${endCol}")
2198
+ $range.Ungroup()
2199
+ @{ success = $true; message = "Ungrouped columns ${startCol} to ${endCol}" } | ConvertTo-Json -Compress
2200
+ `);
2201
+ }
2202
+ async excelInsertPageBreak(cell, type, sheet) {
2203
+ const sheetScript = sheet ?
2204
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2205
+ '$sheet = $workbook.ActiveSheet';
2206
+ return this.executePowerShell(`
2207
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2208
+ $workbook = $excel.ActiveWorkbook
2209
+ ${sheetScript}
2210
+ $cell = $sheet.Range("${cell}")
2211
+ $cell.PageBreak = -4135
2212
+ @{ success = $true; message = "Inserted ${type} page break at ${cell}" } | ConvertTo-Json -Compress
2213
+ `);
2214
+ }
2215
+ async excelDeletePageBreak(cell, type, sheet) {
2216
+ const sheetScript = sheet ?
2217
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2218
+ '$sheet = $workbook.ActiveSheet';
2219
+ return this.executePowerShell(`
2220
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2221
+ $workbook = $excel.ActiveWorkbook
2222
+ ${sheetScript}
2223
+ $cell = $sheet.Range("${cell}")
2224
+ $cell.PageBreak = -4142
2225
+ @{ success = $true; message = "Deleted ${type} page break at ${cell}" } | ConvertTo-Json -Compress
2226
+ `);
2227
+ }
2228
+ async excelResetAllPageBreaks(sheet) {
2229
+ const sheetScript = sheet ?
2230
+ `$sheet = $workbook.Sheets('${sheet.replace(/'/g, "''")}')` :
2231
+ '$sheet = $workbook.ActiveSheet';
2232
+ return this.executePowerShell(`
2233
+ $excel = [Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
2234
+ $workbook = $excel.ActiveWorkbook
2235
+ ${sheetScript}
2236
+ $sheet.ResetAllPageBreaks()
2237
+ @{ success = $true; message = "Reset all page breaks" } | ConvertTo-Json -Compress
2238
+ `);
2239
+ }
2240
+ }
2241
+ export const excelClient = new ExcelClient();
2242
+ //# sourceMappingURL=excel-client.js.map