xlwings-server 1.1.0__py3-none-any.whl

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 (313) hide show
  1. xlwings_server/.env.template +145 -0
  2. xlwings_server/__init__.py +12 -0
  3. xlwings_server/_version.py +34 -0
  4. xlwings_server/auth/__init__.py +0 -0
  5. xlwings_server/auth/custom/__init__.py +26 -0
  6. xlwings_server/auth/entraid/__init__.py +131 -0
  7. xlwings_server/auth/entraid/jwks.py +10 -0
  8. xlwings_server/azure_functions_templates/.funcignore +28 -0
  9. xlwings_server/azure_functions_templates/function_app.py +28 -0
  10. xlwings_server/azure_functions_templates/host.json +22 -0
  11. xlwings_server/azure_functions_templates/local.settings.json +8 -0
  12. xlwings_server/build_utils/__init__.py +9 -0
  13. xlwings_server/build_utils/static_file_hasher.py +212 -0
  14. xlwings_server/cli.py +1592 -0
  15. xlwings_server/config.py +228 -0
  16. xlwings_server/custom_functions/__init__.py +8 -0
  17. xlwings_server/custom_functions/examples.py +177 -0
  18. xlwings_server/custom_scripts/__init__.py +8 -0
  19. xlwings_server/custom_scripts/examples.py +94 -0
  20. xlwings_server/databases.py +19 -0
  21. xlwings_server/dependencies.py +126 -0
  22. xlwings_server/docker_templates/.dockerignore +15 -0
  23. xlwings_server/docker_templates/Dockerfile +60 -0
  24. xlwings_server/docker_templates/docker-compose.yaml +32 -0
  25. xlwings_server/hotreload.py +59 -0
  26. xlwings_server/main.py +242 -0
  27. xlwings_server/models/__init__.py +14 -0
  28. xlwings_server/models/user.py +53 -0
  29. xlwings_server/object_handles.py +142 -0
  30. xlwings_server/routers/__init__.py +0 -0
  31. xlwings_server/routers/manifest.py +82 -0
  32. xlwings_server/routers/root.py +16 -0
  33. xlwings_server/routers/socketio.py +69 -0
  34. xlwings_server/routers/taskpane.py +12 -0
  35. xlwings_server/routers/xlwings.py +197 -0
  36. xlwings_server/security_headers.json +53 -0
  37. xlwings_server/serializers/__init__.py +25 -0
  38. xlwings_server/serializers/default_serializer.py +19 -0
  39. xlwings_server/serializers/dictionary_serializer.py +25 -0
  40. xlwings_server/serializers/framework.py +50 -0
  41. xlwings_server/serializers/numpy_serializer.py +26 -0
  42. xlwings_server/serializers/pandas_serializer.py +95 -0
  43. xlwings_server/static/css/core.css +28 -0
  44. xlwings_server/static/css/style.css +0 -0
  45. xlwings_server/static/images/favicon.png +0 -0
  46. xlwings_server/static/images/xlwings-16.png +0 -0
  47. xlwings_server/static/images/xlwings-32.png +0 -0
  48. xlwings_server/static/images/xlwings-64.png +0 -0
  49. xlwings_server/static/images/xlwings-80.png +0 -0
  50. xlwings_server/static/js/auth.js +13 -0
  51. xlwings_server/static/js/config.js +4 -0
  52. xlwings_server/static/js/core/alpinejs-csp-boilerplate.js +11 -0
  53. xlwings_server/static/js/core/bootstrap-customizations.js +7 -0
  54. xlwings_server/static/js/core/custom-functions-code.js +296 -0
  55. xlwings_server/static/js/core/examples.js +62 -0
  56. xlwings_server/static/js/core/hotreload.js +3 -0
  57. xlwings_server/static/js/core/htmx-handlers.js +86 -0
  58. xlwings_server/static/js/core/officejs-history-fix-part1.js +3 -0
  59. xlwings_server/static/js/core/officejs-history-fix-part2.js +2 -0
  60. xlwings_server/static/js/core/reload-custom-functions.js +79 -0
  61. xlwings_server/static/js/core/socketio-handlers.js +34 -0
  62. xlwings_server/static/js/core/xlwings-alert.js +22 -0
  63. xlwings_server/static/js/core/xlwingsjs/alert.js +85 -0
  64. xlwings_server/static/js/core/xlwingsjs/auth.js +63 -0
  65. xlwings_server/static/js/core/xlwingsjs/sheet-buttons.js +133 -0
  66. xlwings_server/static/js/core/xlwingsjs/utils.js +119 -0
  67. xlwings_server/static/js/core/xlwingsjs/wasm.js +131 -0
  68. xlwings_server/static/js/core/xlwingsjs/xlwings.js +1060 -0
  69. xlwings_server/static/js/main.js +0 -0
  70. xlwings_server/static/js/ribbon.js +17 -0
  71. xlwings_server/static/vendor/@alpinejs/LICENSE +21 -0
  72. xlwings_server/static/vendor/@alpinejs/csp/dist/cdn.min.js +7 -0
  73. xlwings_server/static/vendor/@microsoft/office-js/LICENSE.md +76 -0
  74. xlwings_server/static/vendor/@microsoft/office-js/dist/af-za/office_strings.js +8 -0
  75. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/agaveerrorux.js +18 -0
  76. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/agavedefaulticon32x32.png +0 -0
  77. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/agavedefaulticon96x96.png +0 -0
  78. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/businessbarclose_16x16x32.png +0 -0
  79. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/dropdownarrow_16x16x32.png +0 -0
  80. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/ellipsis_16x16x32.png +0 -0
  81. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/miniinfoblue_16x16x32.png +0 -0
  82. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/moe_default_icon.png +0 -0
  83. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/moe_status_icons.png +0 -0
  84. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/office.png +0 -0
  85. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/images/refresh_16x16x32.png +0 -0
  86. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/index.html +16 -0
  87. xlwings_server/static/vendor/@microsoft/office-js/dist/agaveerrorux/style/agaveerrorux.css +482 -0
  88. xlwings_server/static/vendor/@microsoft/office-js/dist/am-et/office_strings.js +1 -0
  89. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-ae/office_strings.js +8 -0
  90. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-bh/office_strings.js +8 -0
  91. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-dz/office_strings.js +8 -0
  92. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-eg/office_strings.js +8 -0
  93. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-iq/office_strings.js +8 -0
  94. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-jo/office_strings.js +8 -0
  95. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-kw/office_strings.js +8 -0
  96. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-lb/office_strings.js +8 -0
  97. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-ly/office_strings.js +8 -0
  98. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-ma/office_strings.js +8 -0
  99. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-om/office_strings.js +8 -0
  100. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-qa/office_strings.js +8 -0
  101. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-sa/office_strings.js +1 -0
  102. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-sy/office_strings.js +8 -0
  103. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-tn/office_strings.js +8 -0
  104. xlwings_server/static/vendor/@microsoft/office-js/dist/ar-ye/office_strings.js +8 -0
  105. xlwings_server/static/vendor/@microsoft/office-js/dist/ariatelemetry/aria-web-telemetry-2.8.0.min.js +2 -0
  106. xlwings_server/static/vendor/@microsoft/office-js/dist/ariatelemetry/aria-web-telemetry-2.9.0.min.js +2 -0
  107. xlwings_server/static/vendor/@microsoft/office-js/dist/ariatelemetry/aria-web-telemetry.js +1 -0
  108. xlwings_server/static/vendor/@microsoft/office-js/dist/az-latn-az/office_strings.js +8 -0
  109. xlwings_server/static/vendor/@microsoft/office-js/dist/be-by/office_strings.js +8 -0
  110. xlwings_server/static/vendor/@microsoft/office-js/dist/bg-bg/office_strings.js +1 -0
  111. xlwings_server/static/vendor/@microsoft/office-js/dist/bn-in/office_strings.js +1 -0
  112. xlwings_server/static/vendor/@microsoft/office-js/dist/bs-latn-ba/office_strings.js +8 -0
  113. xlwings_server/static/vendor/@microsoft/office-js/dist/ca-es/office_strings.js +1 -0
  114. xlwings_server/static/vendor/@microsoft/office-js/dist/cs-cz/office_strings.js +1 -0
  115. xlwings_server/static/vendor/@microsoft/office-js/dist/cy-gb/office_strings.js +1 -0
  116. xlwings_server/static/vendor/@microsoft/office-js/dist/da-dk/office_strings.js +1 -0
  117. xlwings_server/static/vendor/@microsoft/office-js/dist/de-at/office_strings.js +8 -0
  118. xlwings_server/static/vendor/@microsoft/office-js/dist/de-ch/office_strings.js +8 -0
  119. xlwings_server/static/vendor/@microsoft/office-js/dist/de-de/office_strings.js +1 -0
  120. xlwings_server/static/vendor/@microsoft/office-js/dist/de-li/office_strings.js +8 -0
  121. xlwings_server/static/vendor/@microsoft/office-js/dist/de-lu/office_strings.js +8 -0
  122. xlwings_server/static/vendor/@microsoft/office-js/dist/el-gr/office_strings.js +1 -0
  123. xlwings_server/static/vendor/@microsoft/office-js/dist/en-029/office_strings.js +8 -0
  124. xlwings_server/static/vendor/@microsoft/office-js/dist/en-au/office_strings.js +8 -0
  125. xlwings_server/static/vendor/@microsoft/office-js/dist/en-bz/office_strings.js +8 -0
  126. xlwings_server/static/vendor/@microsoft/office-js/dist/en-ca/office_strings.js +8 -0
  127. xlwings_server/static/vendor/@microsoft/office-js/dist/en-gb/office_strings.js +8 -0
  128. xlwings_server/static/vendor/@microsoft/office-js/dist/en-ie/office_strings.js +8 -0
  129. xlwings_server/static/vendor/@microsoft/office-js/dist/en-in/office_strings.js +8 -0
  130. xlwings_server/static/vendor/@microsoft/office-js/dist/en-jm/office_strings.js +8 -0
  131. xlwings_server/static/vendor/@microsoft/office-js/dist/en-my/office_strings.js +8 -0
  132. xlwings_server/static/vendor/@microsoft/office-js/dist/en-nz/office_strings.js +8 -0
  133. xlwings_server/static/vendor/@microsoft/office-js/dist/en-ph/office_strings.js +8 -0
  134. xlwings_server/static/vendor/@microsoft/office-js/dist/en-sg/office_strings.js +8 -0
  135. xlwings_server/static/vendor/@microsoft/office-js/dist/en-tt/office_strings.js +8 -0
  136. xlwings_server/static/vendor/@microsoft/office-js/dist/en-us/office_strings.js +8 -0
  137. xlwings_server/static/vendor/@microsoft/office-js/dist/en-za/office_strings.js +8 -0
  138. xlwings_server/static/vendor/@microsoft/office-js/dist/en-zw/office_strings.js +8 -0
  139. xlwings_server/static/vendor/@microsoft/office-js/dist/es-ar/office_strings.js +8 -0
  140. xlwings_server/static/vendor/@microsoft/office-js/dist/es-bo/office_strings.js +8 -0
  141. xlwings_server/static/vendor/@microsoft/office-js/dist/es-cl/office_strings.js +8 -0
  142. xlwings_server/static/vendor/@microsoft/office-js/dist/es-co/office_strings.js +8 -0
  143. xlwings_server/static/vendor/@microsoft/office-js/dist/es-cr/office_strings.js +8 -0
  144. xlwings_server/static/vendor/@microsoft/office-js/dist/es-do/office_strings.js +8 -0
  145. xlwings_server/static/vendor/@microsoft/office-js/dist/es-ec/office_strings.js +8 -0
  146. xlwings_server/static/vendor/@microsoft/office-js/dist/es-es/office_strings.js +1 -0
  147. xlwings_server/static/vendor/@microsoft/office-js/dist/es-gt/office_strings.js +8 -0
  148. xlwings_server/static/vendor/@microsoft/office-js/dist/es-hn/office_strings.js +8 -0
  149. xlwings_server/static/vendor/@microsoft/office-js/dist/es-mx/office_strings.js +1 -0
  150. xlwings_server/static/vendor/@microsoft/office-js/dist/es-ni/office_strings.js +8 -0
  151. xlwings_server/static/vendor/@microsoft/office-js/dist/es-pa/office_strings.js +8 -0
  152. xlwings_server/static/vendor/@microsoft/office-js/dist/es-pe/office_strings.js +8 -0
  153. xlwings_server/static/vendor/@microsoft/office-js/dist/es-pr/office_strings.js +8 -0
  154. xlwings_server/static/vendor/@microsoft/office-js/dist/es-py/office_strings.js +8 -0
  155. xlwings_server/static/vendor/@microsoft/office-js/dist/es-sv/office_strings.js +8 -0
  156. xlwings_server/static/vendor/@microsoft/office-js/dist/es-us/office_strings.js +8 -0
  157. xlwings_server/static/vendor/@microsoft/office-js/dist/es-uy/office_strings.js +8 -0
  158. xlwings_server/static/vendor/@microsoft/office-js/dist/es-ve/office_strings.js +8 -0
  159. xlwings_server/static/vendor/@microsoft/office-js/dist/es6-promise.js +5 -0
  160. xlwings_server/static/vendor/@microsoft/office-js/dist/et-ee/office_strings.js +1 -0
  161. xlwings_server/static/vendor/@microsoft/office-js/dist/eu-es/office_strings.js +1 -0
  162. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-15.01.js +11 -0
  163. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-15.02.js +11 -0
  164. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-15.js +11 -0
  165. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-mac-16.00-core.js +11 -0
  166. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-mac-16.00.js +25 -0
  167. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-web-16.00-core.js +11 -0
  168. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-web-16.00.js +25 -0
  169. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-win32-16.00.js +19 -0
  170. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-win32-16.01-core.js +11 -0
  171. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-win32-16.01.js +25 -0
  172. xlwings_server/static/vendor/@microsoft/office-js/dist/excel-winrt-16.00.js +25 -0
  173. xlwings_server/static/vendor/@microsoft/office-js/dist/excelios-15.js +11 -0
  174. xlwings_server/static/vendor/@microsoft/office-js/dist/excelwebapp-15.01.js +11 -0
  175. xlwings_server/static/vendor/@microsoft/office-js/dist/excelwebapp-15.02.js +11 -0
  176. xlwings_server/static/vendor/@microsoft/office-js/dist/excelwebapp-15.js +11 -0
  177. xlwings_server/static/vendor/@microsoft/office-js/dist/fa-ir/office_strings.js +1 -0
  178. xlwings_server/static/vendor/@microsoft/office-js/dist/fi-fi/office_strings.js +1 -0
  179. xlwings_server/static/vendor/@microsoft/office-js/dist/fil-ph/office_strings.js +1 -0
  180. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-be/office_strings.js +8 -0
  181. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-ca/office_strings.js +1 -0
  182. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-ch/office_strings.js +8 -0
  183. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-fr/office_strings.js +1 -0
  184. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-lu/office_strings.js +8 -0
  185. xlwings_server/static/vendor/@microsoft/office-js/dist/fr-mc/office_strings.js +8 -0
  186. xlwings_server/static/vendor/@microsoft/office-js/dist/ga-ie/office_strings.js +8 -0
  187. xlwings_server/static/vendor/@microsoft/office-js/dist/gl-es/office_strings.js +1 -0
  188. xlwings_server/static/vendor/@microsoft/office-js/dist/gu-in/office_strings.js +1 -0
  189. xlwings_server/static/vendor/@microsoft/office-js/dist/he-il/office_strings.js +1 -0
  190. xlwings_server/static/vendor/@microsoft/office-js/dist/hi-in/office_strings.js +1 -0
  191. xlwings_server/static/vendor/@microsoft/office-js/dist/hr-ba/office_strings.js +8 -0
  192. xlwings_server/static/vendor/@microsoft/office-js/dist/hr-hr/office_strings.js +1 -0
  193. xlwings_server/static/vendor/@microsoft/office-js/dist/html2canvas.js +8 -0
  194. xlwings_server/static/vendor/@microsoft/office-js/dist/hu-hu/office_strings.js +1 -0
  195. xlwings_server/static/vendor/@microsoft/office-js/dist/hy-am/office_strings.js +8 -0
  196. xlwings_server/static/vendor/@microsoft/office-js/dist/id-id/office_strings.js +1 -0
  197. xlwings_server/static/vendor/@microsoft/office-js/dist/is-is/office_strings.js +1 -0
  198. xlwings_server/static/vendor/@microsoft/office-js/dist/it-ch/office_strings.js +8 -0
  199. xlwings_server/static/vendor/@microsoft/office-js/dist/it-it/office_strings.js +1 -0
  200. xlwings_server/static/vendor/@microsoft/office-js/dist/ja-jp/office_strings.js +1 -0
  201. xlwings_server/static/vendor/@microsoft/office-js/dist/ka-ge/office_strings.js +8 -0
  202. xlwings_server/static/vendor/@microsoft/office-js/dist/kk-kz/office_strings.js +1 -0
  203. xlwings_server/static/vendor/@microsoft/office-js/dist/km-kh/office_strings.js +8 -0
  204. xlwings_server/static/vendor/@microsoft/office-js/dist/kn-in/office_strings.js +1 -0
  205. xlwings_server/static/vendor/@microsoft/office-js/dist/ko-kr/office_strings.js +1 -0
  206. xlwings_server/static/vendor/@microsoft/office-js/dist/lb-lu/office_strings.js +8 -0
  207. xlwings_server/static/vendor/@microsoft/office-js/dist/lo-la/office_strings.js +1 -0
  208. xlwings_server/static/vendor/@microsoft/office-js/dist/lt-lt/office_strings.js +1 -0
  209. xlwings_server/static/vendor/@microsoft/office-js/dist/lv-lv/office_strings.js +1 -0
  210. xlwings_server/static/vendor/@microsoft/office-js/dist/mk-mk/office_strings.js +8 -0
  211. xlwings_server/static/vendor/@microsoft/office-js/dist/ml-in/office_strings.js +1 -0
  212. xlwings_server/static/vendor/@microsoft/office-js/dist/mn-mn/office_strings.js +8 -0
  213. xlwings_server/static/vendor/@microsoft/office-js/dist/mr-in/office_strings.js +1 -0
  214. xlwings_server/static/vendor/@microsoft/office-js/dist/ms-bn/office_strings.js +8 -0
  215. xlwings_server/static/vendor/@microsoft/office-js/dist/ms-my/office_strings.js +1 -0
  216. xlwings_server/static/vendor/@microsoft/office-js/dist/mt-mt/office_strings.js +8 -0
  217. xlwings_server/static/vendor/@microsoft/office-js/dist/nb-no/office_strings.js +1 -0
  218. xlwings_server/static/vendor/@microsoft/office-js/dist/ne-np/office_strings.js +8 -0
  219. xlwings_server/static/vendor/@microsoft/office-js/dist/nl-be/office_strings.js +8 -0
  220. xlwings_server/static/vendor/@microsoft/office-js/dist/nl-nl/office_strings.js +1 -0
  221. xlwings_server/static/vendor/@microsoft/office-js/dist/nn-no/office_strings.js +1 -0
  222. xlwings_server/static/vendor/@microsoft/office-js/dist/o15apptofilemappingtable.js +11 -0
  223. xlwings_server/static/vendor/@microsoft/office-js/dist/office-vsdoc.js +28596 -0
  224. xlwings_server/static/vendor/@microsoft/office-js/dist/office.js +84 -0
  225. xlwings_server/static/vendor/@microsoft/office-js/dist/pl-pl/office_strings.js +1 -0
  226. xlwings_server/static/vendor/@microsoft/office-js/dist/pt-br/office_strings.js +1 -0
  227. xlwings_server/static/vendor/@microsoft/office-js/dist/pt-pt/office_strings.js +1 -0
  228. xlwings_server/static/vendor/@microsoft/office-js/dist/ro-ro/office_strings.js +1 -0
  229. xlwings_server/static/vendor/@microsoft/office-js/dist/ru-ru/office_strings.js +1 -0
  230. xlwings_server/static/vendor/@microsoft/office-js/dist/si-lk/office_strings.js +8 -0
  231. xlwings_server/static/vendor/@microsoft/office-js/dist/sk-sk/office_strings.js +1 -0
  232. xlwings_server/static/vendor/@microsoft/office-js/dist/sl-si/office_strings.js +1 -0
  233. xlwings_server/static/vendor/@microsoft/office-js/dist/sq-al/office_strings.js +8 -0
  234. xlwings_server/static/vendor/@microsoft/office-js/dist/sr-cyrl-cs/office_strings.js +1 -0
  235. xlwings_server/static/vendor/@microsoft/office-js/dist/sr-cyrl-rs/office_strings.js +1 -0
  236. xlwings_server/static/vendor/@microsoft/office-js/dist/sr-latn-cs/office_strings.js +1 -0
  237. xlwings_server/static/vendor/@microsoft/office-js/dist/sr-latn-rs/office_strings.js +1 -0
  238. xlwings_server/static/vendor/@microsoft/office-js/dist/sv-fi/office_strings.js +8 -0
  239. xlwings_server/static/vendor/@microsoft/office-js/dist/sv-se/office_strings.js +1 -0
  240. xlwings_server/static/vendor/@microsoft/office-js/dist/sw-ke/office_strings.js +1 -0
  241. xlwings_server/static/vendor/@microsoft/office-js/dist/ta-in/office_strings.js +1 -0
  242. xlwings_server/static/vendor/@microsoft/office-js/dist/te-in/office_strings.js +1 -0
  243. xlwings_server/static/vendor/@microsoft/office-js/dist/telemetry/oteljs.js +1 -0
  244. xlwings_server/static/vendor/@microsoft/office-js/dist/telemetry/oteljs_agave.js +1 -0
  245. xlwings_server/static/vendor/@microsoft/office-js/dist/th-th/office_strings.js +1 -0
  246. xlwings_server/static/vendor/@microsoft/office-js/dist/tr-tr/office_strings.js +1 -0
  247. xlwings_server/static/vendor/@microsoft/office-js/dist/uk-ua/office_strings.js +1 -0
  248. xlwings_server/static/vendor/@microsoft/office-js/dist/ur-pk/office_strings.js +1 -0
  249. xlwings_server/static/vendor/@microsoft/office-js/dist/vi-vn/office_strings.js +1 -0
  250. xlwings_server/static/vendor/@microsoft/office-js/dist/webauth/webauth.browserauth.js +77 -0
  251. xlwings_server/static/vendor/@microsoft/office-js/dist/webauth/webauth.implicit.js +35 -0
  252. xlwings_server/static/vendor/@microsoft/office-js/dist/zh-cn/office_strings.js +1 -0
  253. xlwings_server/static/vendor/@microsoft/office-js/dist/zh-hk/office_strings.js +8 -0
  254. xlwings_server/static/vendor/@microsoft/office-js/dist/zh-mo/office_strings.js +8 -0
  255. xlwings_server/static/vendor/@microsoft/office-js/dist/zh-sg/office_strings.js +8 -0
  256. xlwings_server/static/vendor/@microsoft/office-js/dist/zh-tw/office_strings.js +1 -0
  257. xlwings_server/static/vendor/axios/dist/axios.min.js +3 -0
  258. xlwings_server/static/vendor/axios/dist/axios.min.js.map +1 -0
  259. xlwings_server/static/vendor/bootstrap/LICENSE +21 -0
  260. xlwings_server/static/vendor/bootstrap/dist/js/bootstrap.bundle.min.js +7 -0
  261. xlwings_server/static/vendor/bootstrap/dist/js/bootstrap.bundle.min.js.map +1 -0
  262. xlwings_server/static/vendor/bootstrap-xlwings/dist/bootstrap-xlwings.min.css +12 -0
  263. xlwings_server/static/vendor/bootstrap-xlwings/dist/bootstrap-xlwings.min.css.map +1 -0
  264. xlwings_server/static/vendor/htmx-ext-head-support/head-support.js +144 -0
  265. xlwings_server/static/vendor/htmx-ext-loading-states/loading-states.js +184 -0
  266. xlwings_server/static/vendor/htmx.org/LICENSE +13 -0
  267. xlwings_server/static/vendor/htmx.org/dist/htmx.min.js +1 -0
  268. xlwings_server/static/vendor/socket.io/LICENSE +22 -0
  269. xlwings_server/static/vendor/socket.io/client-dist/socket.io.min.js +7 -0
  270. xlwings_server/static/vendor/socket.io/client-dist/socket.io.min.js.map +1 -0
  271. xlwings_server/templates/_book.html +8 -0
  272. xlwings_server/templates/alert_base.html +16 -0
  273. xlwings_server/templates/base.html +117 -0
  274. xlwings_server/templates/examples/alpine/README.md +26 -0
  275. xlwings_server/templates/examples/alpine/taskpane.html +47 -0
  276. xlwings_server/templates/examples/auth/README.md +38 -0
  277. xlwings_server/templates/examples/auth/protected.html +8 -0
  278. xlwings_server/templates/examples/auth/public.html +11 -0
  279. xlwings_server/templates/examples/excel_object_model/README.md +49 -0
  280. xlwings_server/templates/examples/excel_object_model/add_name_form.html +27 -0
  281. xlwings_server/templates/examples/hello_world/README.md +9 -0
  282. xlwings_server/templates/examples/hello_world/taskpane_hello.html +24 -0
  283. xlwings_server/templates/examples/htmx_form/README.md +44 -0
  284. xlwings_server/templates/examples/htmx_form/_greeting.html +6 -0
  285. xlwings_server/templates/examples/htmx_form/taskpane_htmx_form.html +21 -0
  286. xlwings_server/templates/examples/live_form_validation/README.md +60 -0
  287. xlwings_server/templates/examples/live_form_validation/add_name_form.html +33 -0
  288. xlwings_server/templates/examples/multi_app/README.md +34 -0
  289. xlwings_server/templates/examples/multi_app/taskpane1.html +7 -0
  290. xlwings_server/templates/examples/multi_app/taskpane2.html +7 -0
  291. xlwings_server/templates/examples/multi_app/taskpane_loader.html +5 -0
  292. xlwings_server/templates/examples/navigation/README.md +28 -0
  293. xlwings_server/templates/examples/navigation/_navigation.html +16 -0
  294. xlwings_server/templates/examples/navigation/taskpane_one.html +8 -0
  295. xlwings_server/templates/examples/navigation/taskpane_three.html +8 -0
  296. xlwings_server/templates/examples/navigation/taskpane_two.html +8 -0
  297. xlwings_server/templates/examples/pictures/README.md +42 -0
  298. xlwings_server/templates/examples/pictures/_picture.html +4 -0
  299. xlwings_server/templates/examples/pictures/taskpane_pictures.html +26 -0
  300. xlwings_server/templates/manifest.xml +155 -0
  301. xlwings_server/templates/taskpane.html +1 -0
  302. xlwings_server/templates/xlwings_alert.html +27 -0
  303. xlwings_server/templates.py +61 -0
  304. xlwings_server/utils.py +32 -0
  305. xlwings_server/wasm/__init__.py +0 -0
  306. xlwings_server/wasm/config.py +24 -0
  307. xlwings_server/wasm/main.py +236 -0
  308. xlwings_server/wasm/requirements.txt +5 -0
  309. xlwings_server-1.1.0.dist-info/METADATA +61 -0
  310. xlwings_server-1.1.0.dist-info/RECORD +313 -0
  311. xlwings_server-1.1.0.dist-info/WHEEL +4 -0
  312. xlwings_server-1.1.0.dist-info/entry_points.txt +2 -0
  313. xlwings_server-1.1.0.dist-info/licenses/LICENSE.md +223 -0
@@ -0,0 +1,1060 @@
1
+ import { xlAlert } from "./alert.js";
2
+ import { getAccessToken } from "./auth.js";
3
+ export { getAccessToken };
4
+ import {
5
+ getActiveBookName,
6
+ printSupportedApiVersions,
7
+ getCultureInfoName,
8
+ getDateFormat,
9
+ showGlobalError,
10
+ showGlobalStatus,
11
+ hideGlobalError,
12
+ hideGlobalStatus,
13
+ } from "./utils.js";
14
+ export { getActiveBookName, getCultureInfoName, getDateFormat };
15
+ import { pyodideReadyPromise } from "./wasm.js";
16
+ import { registerSheetButtons } from "./sheet-buttons.js";
17
+
18
+ // Prints the supported API versions into the Console
19
+ printSupportedApiVersions();
20
+
21
+ // Namespace
22
+ const xlwings = {
23
+ runPython,
24
+ getAccessToken,
25
+ getActiveBookName,
26
+ getBookData,
27
+ runActions,
28
+ pyodideReadyPromise,
29
+ getCultureInfoName,
30
+ getDateFormat,
31
+ init,
32
+ registerSheetButtons,
33
+ showGlobalError,
34
+ hideGlobalError,
35
+ showGlobalStatus,
36
+ hideGlobalStatus,
37
+ registerCallback,
38
+ };
39
+ globalThis.xlwings = xlwings;
40
+
41
+ // Hook up buttons with the click event upon loading xlwings.js
42
+ document.addEventListener("DOMContentLoaded", init);
43
+
44
+ export async function init() {
45
+ await xlwings.pyodideReadyPromise;
46
+ // Handle unsupported browsers (IE/Edge Legacy)
47
+ if (
48
+ navigator.userAgent.indexOf("Trident") !== -1 ||
49
+ navigator.userAgent.indexOf("Edge") !== -1
50
+ ) {
51
+ showGlobalError(
52
+ "Error: This add-in will not run in your version of Office. Please upgrade " +
53
+ "either to perpetual Office 2021 (or later) or to a Microsoft 365 account.",
54
+ );
55
+ return;
56
+ }
57
+ // Scripts meta
58
+ let scriptsMeta = [];
59
+ if (config.onWasm && !config.isOfficialLiteAddin) {
60
+ scriptsMeta = globalThis.wasmCustomScriptsMeta();
61
+ } else if (!config.isOfficialLiteAddin) {
62
+ const metaUrl =
63
+ window.location.origin +
64
+ config.appPath +
65
+ "/xlwings/custom-scripts-meta.json";
66
+ try {
67
+ const response = await axios.get(metaUrl);
68
+ scriptsMeta = response.data;
69
+ } catch (error) {
70
+ console.error("Error fetching script metadata:", error);
71
+ }
72
+ }
73
+
74
+ // xw-click registration
75
+ const elements = document.querySelectorAll("[xw-click]");
76
+ elements.forEach((element) => {
77
+ // Prevent duplicate initialization when loading partials via htmx
78
+ if (element.hasAttribute("xw-click-initialized")) return;
79
+ element.setAttribute("xw-click-initialized", "true");
80
+ element.addEventListener("click", async (event) => {
81
+ // Clean up error messages
82
+ const globalErrorAlert = document.querySelector("#global-error-alert");
83
+ if (globalErrorAlert) {
84
+ globalErrorAlert.classList.add("d-none");
85
+ }
86
+ element.setAttribute("disabled", "true");
87
+ // Spinner
88
+ const spinner = document.createElement("span");
89
+ spinner.className = "spinner-border spinner-border-sm text-white";
90
+ spinner.setAttribute("role", "status");
91
+ spinner.setAttribute("aria-hidden", "true");
92
+ element.appendChild(spinner);
93
+
94
+ let authResult =
95
+ typeof globalThis.getAuth === "function"
96
+ ? await globalThis.getAuth()
97
+ : { token: "", provider: "" };
98
+ let scriptName = element.getAttribute("xw-click");
99
+
100
+ // Config
101
+ let xwConfig = element.getAttribute("xw-config")
102
+ ? JSON.parse(element.getAttribute("xw-config"))
103
+ : {};
104
+ // Find the script config that matches the current scriptName
105
+ const matchingMeta = scriptsMeta.find(
106
+ (meta) => meta.function_name === scriptName,
107
+ );
108
+ if (matchingMeta) {
109
+ // Override xwConfig with the matched meta's config
110
+ xwConfig = {
111
+ ...xwConfig,
112
+ exclude: matchingMeta.exclude || "",
113
+ include: matchingMeta.include || "",
114
+ };
115
+ }
116
+ // Call runPython and restore button default state
117
+ await runPython({
118
+ ...xwConfig,
119
+ scriptName: scriptName,
120
+ auth: authResult.token,
121
+ headers: { "Auth-Provider": authResult.provider },
122
+ errorDisplayMode: "taskpane",
123
+ });
124
+ element.removeChild(spinner);
125
+ element.removeAttribute("disabled");
126
+ });
127
+ });
128
+ // Handle sheet buttons
129
+ await registerSheetButtons(scriptsMeta);
130
+ }
131
+
132
+ const version = config.xlwingsVersion;
133
+
134
+ globalThis.callbacks = {};
135
+ export async function runPython({
136
+ scriptName = "",
137
+ auth = "",
138
+ include = "",
139
+ exclude = "",
140
+ headers = {},
141
+ errorDisplayMode = "alert",
142
+ } = {}) {
143
+ await Office.onReady();
144
+ try {
145
+ await Excel.run(async (context) => {
146
+ // console.log(payload);
147
+ let payload = await getBookData(
148
+ {
149
+ auth,
150
+ include,
151
+ exclude,
152
+ headers,
153
+ },
154
+ context,
155
+ );
156
+ let rawData;
157
+ if (config.onWasm) {
158
+ // xlwings Wasm
159
+ await pyodideReadyPromise;
160
+ rawData = await globalThis.wasmCustomScriptsCall(payload, scriptName);
161
+ if (rawData.error) {
162
+ console.error(rawData.details);
163
+ throw new Error(rawData.error);
164
+ }
165
+ } else {
166
+ // xlwings Server
167
+ let url =
168
+ window.location.origin +
169
+ config.appPath +
170
+ `/xlwings/custom-scripts-call/${scriptName}`;
171
+ try {
172
+ const response = await axios.post(url, payload, {
173
+ headers: headers,
174
+ timeout: config.requestTimeout * 1000,
175
+ });
176
+ rawData = response.data;
177
+ } catch (error) {
178
+ // TODO: align error handling with xlwings Wasm
179
+ if (error.response) {
180
+ throw (
181
+ (error.response.data && error.response.data.detail) ||
182
+ (error.response.data && error.response.data.error) ||
183
+ (typeof error.response.data === "object"
184
+ ? JSON.stringify(error.response.data)
185
+ : error.response.data) ||
186
+ error.response.statusText ||
187
+ "Unknown server error"
188
+ );
189
+ } else if (error.request) {
190
+ throw "No response received from server";
191
+ } else {
192
+ throw error.message;
193
+ }
194
+ }
195
+ }
196
+ // console.log(rawData);
197
+
198
+ // Run Functions
199
+ // Note that Pyodide returns undefined, so use != and == rather than !== and ===
200
+ if (rawData != null) {
201
+ await runActions(rawData, context);
202
+ }
203
+ });
204
+ } catch (error) {
205
+ console.error(error);
206
+ if (errorDisplayMode === "alert") {
207
+ await xlAlert(error, "Error", "ok", "critical", "");
208
+ } else {
209
+ const globalErrorAlert = document.querySelector("#global-error-alert");
210
+ if (globalErrorAlert) {
211
+ globalErrorAlert.classList.remove("d-none");
212
+ globalErrorAlert.querySelector("span").textContent = error;
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // Helpers
219
+ async function getSelectedRangeAddress(context) {
220
+ let selectionAddress = null;
221
+ try {
222
+ let selection = context.workbook.getSelectedRange().load("address");
223
+ await context.sync();
224
+ selectionAddress = selection.address.split("!").pop();
225
+ } catch (error) {
226
+ // No range is selected (e.g., a shape is selected)
227
+ }
228
+ return selectionAddress;
229
+ }
230
+
231
+ async function getBookData(
232
+ { auth = "", include = "", exclude = "", headers = {} } = {},
233
+ context = null,
234
+ ) {
235
+ // Context
236
+ let bookData;
237
+ if (!context) {
238
+ await Excel.run(async (innerContext) => {
239
+ bookData = await getBookData(
240
+ {
241
+ auth,
242
+ include,
243
+ exclude,
244
+ headers,
245
+ },
246
+ innerContext,
247
+ );
248
+ });
249
+ return bookData;
250
+ }
251
+
252
+ // workbook
253
+ const workbook = context.workbook;
254
+ workbook.load("name");
255
+
256
+ // sheets
257
+ let worksheets = workbook.worksheets;
258
+ worksheets.load("items/name");
259
+ await context.sync();
260
+ let sheets = worksheets.items;
261
+
262
+ // Config
263
+ let configSheet = worksheets.getItemOrNullObject("xlwings.conf");
264
+ await context.sync();
265
+ let config = {};
266
+ if (!configSheet.isNullObject) {
267
+ const configRange = configSheet
268
+ .getRange("A1")
269
+ .getSurroundingRegion()
270
+ .load("values");
271
+ await context.sync();
272
+ const configValues = configRange.values;
273
+ configValues.forEach((el) => (config[el[0].toString()] = el[1].toString()));
274
+ }
275
+
276
+ if (auth === "") {
277
+ auth = config["AUTH"] || "";
278
+ }
279
+
280
+ if (include === "") {
281
+ include = config["INCLUDE"] || "";
282
+ }
283
+ let includeArray = [];
284
+ if (include !== "") {
285
+ includeArray = include.split(",").map((item) => item.trim());
286
+ }
287
+
288
+ if (exclude === "") {
289
+ exclude = config["EXCLUDE"] || "";
290
+ }
291
+ let excludeArray = [];
292
+ if (exclude !== "") {
293
+ excludeArray = exclude.split(",").map((item) => item.trim());
294
+ }
295
+ if (includeArray.length > 0 && excludeArray.length > 0) {
296
+ throw "Either use 'include' or 'exclude', but not both!";
297
+ }
298
+ if (includeArray.length > 0) {
299
+ sheets.forEach((sheet) => {
300
+ if (!includeArray.includes(sheet.name)) {
301
+ excludeArray.push(sheet.name);
302
+ }
303
+ });
304
+ }
305
+
306
+ if (Object.keys(headers).length === 0) {
307
+ for (const property in config) {
308
+ if (property.toLowerCase().startsWith("header_")) {
309
+ headers[property.substring(7)] = config[property];
310
+ }
311
+ }
312
+ }
313
+ if (!("Authorization" in headers) && auth.length > 0) {
314
+ headers["Authorization"] = auth;
315
+ }
316
+
317
+ // Standard headers
318
+ headers["Content-Type"] = "application/json";
319
+
320
+ // Request payload
321
+ let payload = {};
322
+ payload["client"] = "Office.js";
323
+ payload["version"] = version;
324
+ let activeSheet = worksheets.getActiveWorksheet().load("position");
325
+ await context.sync();
326
+
327
+ // Cell selection address
328
+ const selectionAddress = await getSelectedRangeAddress(context);
329
+
330
+ payload["book"] = {
331
+ name: workbook.name,
332
+ active_sheet_index: activeSheet.position,
333
+ selection: selectionAddress,
334
+ };
335
+
336
+ // Names (book scope)
337
+ let names = [];
338
+ const namedItems = context.workbook.names.load("name, type");
339
+ await context.sync();
340
+
341
+ for (const namedItem of namedItems.items) {
342
+ // Currently filtering to named ranges
343
+ if (namedItem.type === "Range") {
344
+ // Names pointing to multiple Ranges return null
345
+ let range = namedItem.getRangeOrNullObject();
346
+ await context.sync();
347
+ names.push({
348
+ name: namedItem.name,
349
+ sheet: range.isNullObject ? null : range.worksheet.load("position"),
350
+ range: range.isNullObject ? null : range.load("address"),
351
+ scope_sheet_name: null,
352
+ scope_sheet_index: null,
353
+ book_scope: true, // workbook.names contains only workbook scope!
354
+ });
355
+ }
356
+ }
357
+
358
+ await context.sync();
359
+
360
+ let names2 = [];
361
+ names.forEach((namedItem, ix) => {
362
+ names2.push({
363
+ name: namedItem.name,
364
+ sheet_index: namedItem.sheet ? namedItem.sheet.position : null,
365
+ address: namedItem.range
366
+ ? namedItem.range.address.split("!").pop()
367
+ : null,
368
+ scope_sheet_name: null,
369
+ scope_sheet_index: null,
370
+ book_scope: namedItem.book_scope,
371
+ });
372
+ });
373
+
374
+ payload["names"] = names2;
375
+
376
+ // Sheets
377
+ payload["sheets"] = [];
378
+ let sheetsLoader = [];
379
+ sheets.forEach((sheet) => {
380
+ sheet.load("name names");
381
+ let lastCell;
382
+ if (excludeArray.includes(sheet.name)) {
383
+ lastCell = null;
384
+ } else if (sheet.getUsedRange() !== undefined) {
385
+ lastCell = sheet.getUsedRange().getLastCell().load("address");
386
+ } else {
387
+ lastCell = sheet.getRange("A1").load("address");
388
+ }
389
+ sheetsLoader.push({
390
+ sheet: sheet,
391
+ lastCell: lastCell,
392
+ });
393
+ });
394
+
395
+ await context.sync();
396
+
397
+ sheetsLoader.forEach((item, ix) => {
398
+ if (!excludeArray.includes(item["sheet"].name)) {
399
+ let range;
400
+ range = item["sheet"]
401
+ .getRange(`A1:${item["lastCell"].address}`)
402
+ .load("values, numberFormatCategories");
403
+ sheetsLoader[ix]["range"] = range;
404
+ // Names (sheet scope)
405
+ sheetsLoader[ix]["names"] = item["sheet"].names.load("name, type");
406
+ }
407
+ });
408
+
409
+ await context.sync();
410
+
411
+ // Names (sheet scope)
412
+ let namesSheetScope = [];
413
+ for (const item of sheetsLoader) {
414
+ if (!excludeArray.includes(item["sheet"].name)) {
415
+ for (const namedItem of item["names"].items) {
416
+ // Currently filtering to named ranges
417
+ if (namedItem.type === "Range") {
418
+ let range = namedItem.getRangeOrNullObject();
419
+ await context.sync();
420
+ namesSheetScope.push({
421
+ name: namedItem.name,
422
+ sheet: range.isNullObject ? null : range.worksheet.load("position"),
423
+ range: range.isNullObject ? null : range.load("address"),
424
+ scope_sheet: namedItem.worksheet.load("name, position"),
425
+ book_scope: false,
426
+ });
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ await context.sync();
433
+
434
+ let namesSheetsScope2 = [];
435
+ for (const namedItem of namesSheetScope) {
436
+ namesSheetsScope2.push({
437
+ name: namedItem.name,
438
+ sheet_index: namedItem.sheet ? namedItem.sheet.position : null,
439
+ address: namedItem.range
440
+ ? namedItem.range.address.split("!").pop()
441
+ : null,
442
+ scope_sheet_name: namedItem.scope_sheet.name,
443
+ scope_sheet_index: namedItem.scope_sheet.position,
444
+ book_scope: namedItem.book_scope,
445
+ });
446
+ }
447
+
448
+ // Add sheet scoped names to book scoped names
449
+ payload["names"] = payload["names"].concat(namesSheetsScope2);
450
+
451
+ // values
452
+ for (let item of sheetsLoader) {
453
+ let sheet = item["sheet"]; // TODO: replace item["sheet"] with sheet
454
+ let values;
455
+ if (excludeArray.includes(item["sheet"].name)) {
456
+ values = [[]];
457
+ } else {
458
+ values = item["range"].values;
459
+ if (Office.context.requirements.isSetSupported("ExcelApi", "1.12")) {
460
+ // numberFormatCategories requires Excel 2021/365
461
+ // i.e., dates aren't transformed to Python's datetime in Excel <=2019
462
+ let categories = item["range"].numberFormatCategories;
463
+ // Handle dates
464
+ // https://learn.microsoft.com/en-us/office/dev/scripts/resources/samples/excel-samples#dates
465
+ values.forEach((valueRow, rowIndex) => {
466
+ const categoryRow = categories[rowIndex];
467
+ valueRow.forEach((value, colIndex) => {
468
+ const category = categoryRow[colIndex];
469
+ if (
470
+ (category.toString() === "Date" ||
471
+ category.toString() === "Time") &&
472
+ typeof value === "number"
473
+ ) {
474
+ values[rowIndex][colIndex] = new Date(
475
+ Math.round((value - 25569) * 86400 * 1000),
476
+ ).toISOString();
477
+ }
478
+ });
479
+ });
480
+ }
481
+ }
482
+ // Tables
483
+ let tablesArray = [];
484
+ if (!excludeArray.includes(item["sheet"].name)) {
485
+ const tables = sheet.tables.load([
486
+ "name",
487
+ "showHeaders",
488
+ "dataBodyRange",
489
+ "showTotals",
490
+ "style",
491
+ "showFilterButton",
492
+ ]);
493
+ await context.sync();
494
+ let tablesLoader = [];
495
+ for (let table of sheet.tables.items) {
496
+ tablesLoader.push({
497
+ name: table.name,
498
+ showHeaders: table.showHeaders,
499
+ showTotals: table.showTotals,
500
+ style: table.style,
501
+ showFilterButton: table.showFilterButton,
502
+ range: table.getRange().load("address"),
503
+ dataBodyRange: table.getDataBodyRange().load("address"),
504
+ headerRowRange: table.showHeaders
505
+ ? table.getHeaderRowRange().load("address")
506
+ : null,
507
+ totalRowRange: table.showTotals
508
+ ? table.getTotalRowRange().load("address")
509
+ : null,
510
+ });
511
+ }
512
+ await context.sync();
513
+ for (let table of tablesLoader) {
514
+ tablesArray.push({
515
+ name: table.name,
516
+ range_address: table.range.address.split("!").pop(),
517
+ header_row_range_address: table.showHeaders
518
+ ? table.headerRowRange.address.split("!").pop()
519
+ : null,
520
+ data_body_range_address: table.dataBodyRange.address.split("!").pop(),
521
+ total_row_range_address: table.showTotals
522
+ ? table.totalRowRange.address.split("!").pop()
523
+ : null,
524
+ show_headers: table.showHeaders,
525
+ show_totals: table.showTotals,
526
+ table_style: table.style,
527
+ show_autofilter: table.showFilterButton,
528
+ });
529
+ }
530
+ }
531
+
532
+ // Pictures
533
+ let picturesArray = [];
534
+ if (!excludeArray.includes(item["sheet"].name)) {
535
+ const shapes = sheet.shapes.load(["name", "width", "height", "type"]);
536
+ await context.sync();
537
+ for (let shape of sheet.shapes.items) {
538
+ if (shape.type == Excel.ShapeType.image) {
539
+ picturesArray.push({
540
+ name: shape.name,
541
+ height: shape.height,
542
+ width: shape.width,
543
+ });
544
+ }
545
+ }
546
+ }
547
+
548
+ payload["sheets"].push({
549
+ name: item["sheet"].name,
550
+ values: values,
551
+ pictures: picturesArray,
552
+ tables: tablesArray,
553
+ });
554
+ }
555
+ return payload;
556
+ }
557
+
558
+ async function runActions(rawData, context = null) {
559
+ if (typeof rawData === "string") {
560
+ rawData = JSON.parse(rawData);
561
+ }
562
+
563
+ if (!context) {
564
+ return await Excel.run(async (innerContext) => {
565
+ await runActions(rawData, innerContext);
566
+ });
567
+ }
568
+
569
+ const forceSync = ["sheet"];
570
+ for (let action of rawData["actions"]) {
571
+ await globalThis.callbacks[action.func](context, action);
572
+ if (forceSync.some((el) => action.func.toLowerCase().includes(el))) {
573
+ await context.sync();
574
+ }
575
+ }
576
+ }
577
+
578
+ async function getRange(context, action) {
579
+ let sheets = context.workbook.worksheets.load("items");
580
+ await context.sync();
581
+ return sheets.items[action["sheet_position"]].getRangeByIndexes(
582
+ action.start_row,
583
+ action.start_column,
584
+ action.row_count,
585
+ action.column_count,
586
+ );
587
+ }
588
+
589
+ async function getSheet(context, action) {
590
+ let sheets = context.workbook.worksheets.load("items");
591
+ await context.sync();
592
+ return sheets.items[action.sheet_position];
593
+ }
594
+
595
+ async function getTable(context, action) {
596
+ // Requires action.args[0] to be the table index
597
+ let sheets = context.workbook.worksheets.load("items");
598
+ const tables = sheets.items[action.sheet_position].tables.load("items");
599
+ await context.sync();
600
+ return tables.items[parseInt(action.args[0].toString())];
601
+ }
602
+
603
+ async function getShapeByType(context, sheetPosition, shapeIndex, shapeType) {
604
+ let sheets = context.workbook.worksheets.load("items");
605
+ const shapes = sheets.items[sheetPosition].shapes.load("items");
606
+ await context.sync();
607
+ const myshapes = shapes.items.filter((shape) => shape.type === shapeType);
608
+ return myshapes[shapeIndex];
609
+ }
610
+
611
+ export function registerCallback(callback) {
612
+ globalThis.callbacks[callback.name] = callback;
613
+ }
614
+
615
+ // Functions map
616
+ // Didn't find a way to use registerCallback so that webpack won't strip out these
617
+ // functions when optimizing
618
+ let funcs = {
619
+ setValues: setValues,
620
+ addSheet: addSheet,
621
+ setSheetName: setSheetName,
622
+ setAutofit: setAutofit,
623
+ setRangeColor: setRangeColor,
624
+ activateSheet: activateSheet,
625
+ addHyperlink: addHyperlink,
626
+ setNumberFormat: setNumberFormat,
627
+ setPictureName: setPictureName,
628
+ setPictureWidth: setPictureWidth,
629
+ setPictureHeight: setPictureHeight,
630
+ deletePicture: deletePicture,
631
+ addPicture: addPicture,
632
+ updatePicture: updatePicture,
633
+ alert: alert,
634
+ setRangeName: setRangeName,
635
+ namesAdd: namesAdd,
636
+ nameDelete: nameDelete,
637
+ runMacro: runMacro,
638
+ rangeDelete: rangeDelete,
639
+ rangeInsert: rangeInsert,
640
+ rangeSelect: rangeSelect,
641
+ rangeClearContents: rangeClearContents,
642
+ rangeClearFormats: rangeClearFormats,
643
+ rangeGroup: rangeGroup,
644
+ rangeUngroup: rangeUngroup,
645
+ rangeClear: rangeClear,
646
+ rangeAdjustIndent: rangeAdjustIndent,
647
+ addTable: addTable,
648
+ setTableName: setTableName,
649
+ resizeTable: resizeTable,
650
+ showAutofilterTable: showAutofilterTable,
651
+ showHeadersTable: showHeadersTable,
652
+ showTotalsTable: showTotalsTable,
653
+ setTableStyle: setTableStyle,
654
+ copyRange: copyRange,
655
+ copyFromRange: copyFromRange,
656
+ sheetDelete: sheetDelete,
657
+ sheetClear: sheetClear,
658
+ sheetClearFormats: sheetClearFormats,
659
+ sheetClearContents: sheetClearContents,
660
+ freezePaneAtRange: freezePaneAtRange,
661
+ freezePaneUnfreeze: freezePaneUnfreeze,
662
+ setFontProperty: setFontProperty,
663
+ };
664
+
665
+ Object.assign(globalThis.callbacks, funcs);
666
+
667
+ // Callbacks
668
+ async function setFontProperty(context, action) {
669
+ let range = await getRange(context, action);
670
+ let property = action.args[0];
671
+ let value = action.args[1];
672
+ if (property === "bold" || property === "italic") value = Boolean(value);
673
+ range.format.font[property] = value;
674
+ await context.sync();
675
+ }
676
+
677
+ async function setValues(context, action) {
678
+ let range = await getRange(context, action);
679
+ range.values = action.values;
680
+ await context.sync();
681
+ }
682
+
683
+ async function rangeClearContents(context, action) {
684
+ let range = await getRange(context, action);
685
+ range.clear(Excel.ClearApplyTo.contents);
686
+ await context.sync();
687
+ }
688
+
689
+ async function rangeClearFormats(context, action) {
690
+ let range = await getRange(context, action);
691
+ range.clear(Excel.ClearApplyTo.formats);
692
+ await context.sync();
693
+ }
694
+
695
+ async function rangeClear(context, action) {
696
+ let range = await getRange(context, action);
697
+ range.clear(Excel.ClearApplyTo.all);
698
+ await context.sync();
699
+ }
700
+
701
+ async function addSheet(context, action) {
702
+ let sheet;
703
+ if (action.args[1] != null) {
704
+ sheet = context.workbook.worksheets.add(action.args[1].toString());
705
+ } else {
706
+ sheet = context.workbook.worksheets.add();
707
+ }
708
+ sheet.position = parseInt(action.args[0].toString());
709
+ }
710
+
711
+ async function setSheetName(context, action) {
712
+ let sheets = context.workbook.worksheets.load("items");
713
+ sheets.items[action.sheet_position].name = action.args[0].toString();
714
+ }
715
+
716
+ async function setAutofit(context, action) {
717
+ if (action.args[0] === "columns") {
718
+ let range = await getRange(context, action);
719
+ range.format.autofitColumns();
720
+ } else {
721
+ let range = await getRange(context, action);
722
+ range.format.autofitRows();
723
+ }
724
+ }
725
+
726
+ async function setRangeColor(context, action) {
727
+ let range = await getRange(context, action);
728
+ range.format.fill.color = action.args[0].toString();
729
+ await context.sync();
730
+ }
731
+
732
+ async function activateSheet(context, action) {
733
+ let worksheets = context.workbook.worksheets;
734
+ worksheets.load("items");
735
+ await context.sync();
736
+ worksheets.items[parseInt(action.args[0].toString())].activate();
737
+ }
738
+
739
+ async function addHyperlink(context, action) {
740
+ let range = await getRange(context, action);
741
+ let hyperlink = {
742
+ textToDisplay: action.args[1].toString(),
743
+ screenTip: action.args[2].toString(),
744
+ address: action.args[0].toString(),
745
+ };
746
+ range.hyperlink = hyperlink;
747
+ await context.sync();
748
+ }
749
+
750
+ async function setNumberFormat(context, action) {
751
+ let range = await getRange(context, action);
752
+ range.numberFormat = [[action.args[0].toString()]];
753
+ }
754
+
755
+ async function setPictureName(context, action) {
756
+ const myshape = await getShapeByType(
757
+ context,
758
+ action.sheet_position,
759
+ Number(action.args[0]),
760
+ Excel.ShapeType.image,
761
+ );
762
+ myshape.name = action.args[1].toString();
763
+ }
764
+
765
+ async function setPictureHeight(context, action) {
766
+ const myshape = await getShapeByType(
767
+ context,
768
+ action.sheet_position,
769
+ Number(action.args[0]),
770
+ Excel.ShapeType.image,
771
+ );
772
+ myshape.height = Number(action.args[1]);
773
+ }
774
+
775
+ async function setPictureWidth(context, action) {
776
+ const myshape = await getShapeByType(
777
+ context,
778
+ action.sheet_position,
779
+ Number(action.args[0]),
780
+ Excel.ShapeType.image,
781
+ );
782
+ myshape.width = Number(action.args[1]);
783
+ }
784
+
785
+ async function deletePicture(context, action) {
786
+ const myshape = await getShapeByType(
787
+ context,
788
+ action.sheet_position,
789
+ Number(action.args[0]),
790
+ Excel.ShapeType.image,
791
+ );
792
+ myshape.delete();
793
+ }
794
+
795
+ async function addPicture(context, action) {
796
+ const selectedAddress = await getSelectedRangeAddress(context);
797
+
798
+ const imageBase64 = action["args"][0].toString();
799
+ const colIndex = Number(action["args"][1]);
800
+ const rowIndex = Number(action["args"][2]);
801
+ let left = Number(action["args"][3]);
802
+ let top = Number(action["args"][4]);
803
+
804
+ const sheet = await getSheet(context, action);
805
+ let anchorCell = sheet
806
+ .getRangeByIndexes(rowIndex, colIndex, 1, 1)
807
+ .load("left, top");
808
+ await context.sync();
809
+ left = Math.max(left, anchorCell.left);
810
+ top = Math.max(top, anchorCell.top);
811
+ const image = sheet.shapes.addImage(imageBase64);
812
+ image.left = left;
813
+ image.top = top;
814
+
815
+ if (selectedAddress) {
816
+ context.workbook.worksheets
817
+ .getActiveWorksheet()
818
+ .getRange(selectedAddress)
819
+ .select();
820
+ await context.sync();
821
+ }
822
+ }
823
+
824
+ async function updatePicture(context, action) {
825
+ const selectedAddress = await getSelectedRangeAddress(context);
826
+
827
+ const imageBase64 = action["args"][0].toString();
828
+ const sheet = await getSheet(context, action);
829
+ let image = await getShapeByType(
830
+ context,
831
+ action.sheet_position,
832
+ Number(action.args[1]),
833
+ Excel.ShapeType.image,
834
+ );
835
+ image = image.load("name, left, top, height, width");
836
+ await context.sync();
837
+ let imgName = image.name;
838
+ let imgLeft = image.left;
839
+ let imgTop = image.top;
840
+ let imgHeight = image.height;
841
+ let imgWidth = image.width;
842
+ image.delete();
843
+
844
+ const newImage = sheet.shapes.addImage(imageBase64);
845
+ newImage.name = imgName;
846
+ newImage.left = imgLeft;
847
+ newImage.top = imgTop;
848
+ newImage.height = imgHeight;
849
+ newImage.width = imgWidth;
850
+
851
+ if (selectedAddress) {
852
+ context.workbook.worksheets
853
+ .getActiveWorksheet()
854
+ .getRange(selectedAddress)
855
+ .select();
856
+ await context.sync();
857
+ }
858
+ }
859
+
860
+ async function alert(context, action) {
861
+ let myPrompt = action.args[0].toString();
862
+ let myTitle = action.args[1].toString();
863
+ let myButtons = action.args[2].toString();
864
+ let myMode = action.args[3].toString();
865
+ let myCallback = action.args[4].toString();
866
+ xlAlert(myPrompt, myTitle, myButtons, myMode, myCallback);
867
+ }
868
+
869
+ async function setRangeName(context, action) {
870
+ let range = await getRange(context, action);
871
+ context.workbook.names.add(action.args[0].toString(), range);
872
+ }
873
+
874
+ async function namesAdd(context, action) {
875
+ let name = action.args[0].toString();
876
+ let refersTo = action.args[1].toString();
877
+ if (action.sheet_position == null) {
878
+ context.workbook.names.add(name, refersTo);
879
+ } else {
880
+ let sheets = context.workbook.worksheets.load("items");
881
+ await context.sync();
882
+ sheets.items[action.sheet_position].names.add(name, refersTo);
883
+ }
884
+ }
885
+
886
+ async function nameDelete(context, action) {
887
+ let name = action.args[2].toString();
888
+ let book_scope = Boolean(action.args[4]);
889
+ let scope_sheet_index = Number(action.args[5]);
890
+ if (book_scope === true) {
891
+ context.workbook.names.getItem(name).delete();
892
+ } else {
893
+ let sheets = context.workbook.worksheets.load("items");
894
+ await context.sync();
895
+ sheets.items[scope_sheet_index].names.getItem(name).delete();
896
+ }
897
+ }
898
+
899
+ async function runMacro(context, action) {
900
+ await globalThis.callbacks[action.args[0].toString()](
901
+ context,
902
+ ...action.args.slice(1),
903
+ );
904
+ }
905
+
906
+ async function rangeDelete(context, action) {
907
+ let range = await getRange(context, action);
908
+ let shift = action.args[0].toString();
909
+ if (shift === "up") {
910
+ range.delete(Excel.DeleteShiftDirection.up);
911
+ } else if (shift === "left") {
912
+ range.delete(Excel.DeleteShiftDirection.left);
913
+ }
914
+ }
915
+
916
+ async function rangeInsert(context, action) {
917
+ let range = await getRange(context, action);
918
+ let shift = action.args[0].toString();
919
+ if (shift === "down") {
920
+ range.insert(Excel.InsertShiftDirection.down);
921
+ } else if (shift === "right") {
922
+ range.insert(Excel.InsertShiftDirection.right);
923
+ }
924
+ }
925
+
926
+ async function rangeSelect(context, action) {
927
+ let range = await getRange(context, action);
928
+ range.select();
929
+ }
930
+
931
+ async function addTable(context, action) {
932
+ let worksheets = context.workbook.worksheets.load("items");
933
+ await context.sync();
934
+ let mytable = worksheets.items[action.sheet_position].tables.add(
935
+ action.args[0].toString(),
936
+ Boolean(action.args[1]),
937
+ );
938
+ if (action.args[2] != null) {
939
+ mytable.style = action.args[2].toString();
940
+ }
941
+ if (action.args[3] != null) {
942
+ mytable.name = action.args[3].toString();
943
+ }
944
+ }
945
+
946
+ async function setTableName(context, action) {
947
+ const mytable = await getTable(context, action);
948
+ mytable.name = action.args[1].toString();
949
+ }
950
+
951
+ async function resizeTable(context, action) {
952
+ const mytable = await getTable(context, action);
953
+ mytable.resize(action.args[1].toString());
954
+ }
955
+
956
+ async function showAutofilterTable(context, action) {
957
+ const mytable = await getTable(context, action);
958
+ mytable.showFilterButton = Boolean(action.args[1]);
959
+ }
960
+
961
+ async function showHeadersTable(context, action) {
962
+ const mytable = await getTable(context, action);
963
+ mytable.showHeaders = Boolean(action.args[1]);
964
+ }
965
+
966
+ async function showTotalsTable(context, action) {
967
+ const mytable = await getTable(context, action);
968
+ mytable.showTotals = Boolean(action.args[1]);
969
+ }
970
+
971
+ async function setTableStyle(context, action) {
972
+ const mytable = await getTable(context, action);
973
+ mytable.style = action.args[1].toString();
974
+ }
975
+
976
+ async function copyRange(context, action) {
977
+ const destination = context.workbook.worksheets.items[
978
+ parseInt(action.args[0].toString())
979
+ ].getRange(action.args[1].toString());
980
+ destination.copyFrom(await getRange(context, action));
981
+ }
982
+
983
+ async function copyFromRange(context, action) {
984
+ const myRange = await getRange(context, action);
985
+ const sourceRange = context.workbook.worksheets.items[
986
+ parseInt(action.args[0].toString())
987
+ ].getRange(action.args[1].toString());
988
+ const copyType = action.args[2];
989
+ const skipBlanks = Boolean(action.args[3]);
990
+ const transpose = Boolean(action.args[4]);
991
+ myRange.copyFrom(sourceRange, copyType, skipBlanks, transpose);
992
+ }
993
+
994
+ async function sheetDelete(context, action) {
995
+ // TODO: use getSheet
996
+ let worksheets = context.workbook.worksheets.load("items");
997
+ await context.sync();
998
+ worksheets.items[action.sheet_position].delete();
999
+ }
1000
+
1001
+ async function sheetClear(context, action) {
1002
+ // TODO: use getSheet
1003
+ let worksheets = context.workbook.worksheets.load("items");
1004
+ await context.sync();
1005
+ worksheets.items[action.sheet_position]
1006
+ .getRanges()
1007
+ .clear(Excel.ClearApplyTo.all);
1008
+ }
1009
+
1010
+ async function sheetClearFormats(context, action) {
1011
+ // TODO: use getSheet
1012
+ let worksheets = context.workbook.worksheets.load("items");
1013
+ await context.sync();
1014
+ worksheets.items[action.sheet_position]
1015
+ .getRanges()
1016
+ .clear(Excel.ClearApplyTo.formats);
1017
+ }
1018
+
1019
+ async function sheetClearContents(context, action) {
1020
+ // TODO: use getSheet
1021
+ let worksheets = context.workbook.worksheets.load("items");
1022
+ await context.sync();
1023
+ worksheets.items[action.sheet_position]
1024
+ .getRanges()
1025
+ .clear(Excel.ClearApplyTo.contents);
1026
+ }
1027
+
1028
+ async function rangeGroup(context, action) {
1029
+ let myrange = await getRange(context, action);
1030
+ if (action.args[0].toString() == "columns") {
1031
+ myrange.group(Excel.GroupOption.byColumns);
1032
+ } else {
1033
+ myrange.group(Excel.GroupOption.byRows);
1034
+ }
1035
+ }
1036
+
1037
+ async function rangeUngroup(context, action) {
1038
+ let myrange = await getRange(context, action);
1039
+ if (action.args[0].toString() == "columns") {
1040
+ myrange.ungroup(Excel.GroupOption.byColumns);
1041
+ } else {
1042
+ myrange.ungroup(Excel.GroupOption.byRows);
1043
+ }
1044
+ }
1045
+
1046
+ async function freezePaneAtRange(context, action) {
1047
+ let sheet = await getSheet(context, action);
1048
+ let range = sheet.getRange(action.args[0].toString());
1049
+ sheet.freezePanes.freezeAt(range);
1050
+ }
1051
+
1052
+ async function freezePaneUnfreeze(context, action) {
1053
+ let sheet = await getSheet(context, action);
1054
+ sheet.freezePanes.unfreeze();
1055
+ }
1056
+
1057
+ async function rangeAdjustIndent(context, action) {
1058
+ let range = await getRange(context, action);
1059
+ range.format.adjustIndent(parseInt(action.args[0].toString()));
1060
+ }