@v587d/capital-generation 2.29.0 → 2.30.1

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 (305) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +16 -0
  4. package/automation/package.json +1 -1
  5. package/chart-ui/package.json +1 -1
  6. package/config/package.json +1 -1
  7. package/lib/collector-runtime.js +56 -1
  8. package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
  9. package/lib/data-collector/catalog-taxonomy.js +33 -0
  10. package/lib/data-collector/dataset-tools.js +4 -2
  11. package/lib/data-collector/describe.d.ts +2 -0
  12. package/lib/data-collector/describe.js +2 -0
  13. package/lib/data-collector/store.d.ts +11 -0
  14. package/lib/data-collector/store.js +80 -1
  15. package/lib/data-collector/tools.d.ts +1 -1
  16. package/lib/data-collector/tools.js +10 -9
  17. package/lib/python-runtime/errors.d.ts +1 -1
  18. package/lib/python-runtime/errors.js +2 -0
  19. package/lib/python-runtime/manager.d.ts +28 -1
  20. package/lib/python-runtime/manager.js +141 -5
  21. package/lib/python-runtime/probe.d.ts +24 -0
  22. package/lib/python-runtime/probe.js +66 -50
  23. package/lib/sources/csindex-http.d.ts +4 -0
  24. package/lib/sources/csindex-http.js +233 -0
  25. package/lib/sources/eastmoney-http.js +1504 -1
  26. package/lib/sources/fuyao-rest.js +168 -8
  27. package/lib/sources/official-http.d.ts +4 -0
  28. package/lib/sources/official-http.js +477 -0
  29. package/lib/sources/python-remote.d.ts +25 -0
  30. package/lib/sources/python-remote.js +461 -0
  31. package/lib/sources/sina-http.d.ts +2 -0
  32. package/lib/sources/sina-http.js +484 -0
  33. package/lib/sources/tencent-http.js +23 -8
  34. package/lib/sources/ths-http.d.ts +2 -0
  35. package/lib/sources/ths-http.js +517 -0
  36. package/lib/time/tools.js +19 -0
  37. package/lib/web-retriever/local-fetch.d.ts +1 -1
  38. package/lib/web-retriever/local-fetch.js +1 -1
  39. package/lib/web-retriever/sources.d.ts +7 -0
  40. package/lib/web-retriever/sources.js +46 -21
  41. package/lib/web-retriever/throttle.d.ts +8 -0
  42. package/lib/web-retriever/throttle.js +13 -0
  43. package/lib/web-retriever/tools.js +1 -1
  44. package/lib/web-retriever/wind-client.d.ts +1 -1
  45. package/lib/web-retriever/wind-client.js +1 -1
  46. package/package.json +1 -1
  47. package/preset/capital-generation/agent.patch.yml +7 -5
  48. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
  49. package/python/scripts/baostock_stock_basic.py +129 -0
  50. package/python/scripts/baostock_valuation_history.py +141 -0
  51. package/python/scripts/pbc_social_financing.py +291 -0
  52. package/python/vendor/baostock/LICENSE +19 -0
  53. package/python/vendor/baostock/__init__.py +42 -0
  54. package/python/vendor/baostock/common/__init__.py +0 -0
  55. package/python/vendor/baostock/common/contants.py +189 -0
  56. package/python/vendor/baostock/common/context.py +4 -0
  57. package/python/vendor/baostock/corpreport/__init__.py +0 -0
  58. package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
  59. package/python/vendor/baostock/data/__init__.py +0 -0
  60. package/python/vendor/baostock/data/messageheader.py +17 -0
  61. package/python/vendor/baostock/data/msg.py +21 -0
  62. package/python/vendor/baostock/data/resultset.py +200 -0
  63. package/python/vendor/baostock/demo/__init__.py +0 -0
  64. package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
  65. package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
  66. package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
  67. package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
  68. package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
  69. package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
  70. package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
  71. package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
  72. package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
  73. package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
  74. package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
  75. package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
  76. package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
  77. package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
  78. package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
  79. package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
  80. package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
  81. package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
  82. package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
  83. package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
  84. package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
  85. package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
  86. package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
  87. package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
  88. package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
  89. package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
  90. package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
  91. package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
  92. package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
  93. package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
  94. package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
  95. package/python/vendor/baostock/evaluation/__init__.py +0 -0
  96. package/python/vendor/baostock/evaluation/season_index.py +758 -0
  97. package/python/vendor/baostock/login/__init__.py +0 -0
  98. package/python/vendor/baostock/login/loginout.py +230 -0
  99. package/python/vendor/baostock/macroscopic/__init__.py +0 -0
  100. package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
  101. package/python/vendor/baostock/metadata/__init__.py +0 -0
  102. package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
  103. package/python/vendor/baostock/security/__init__.py +0 -0
  104. package/python/vendor/baostock/security/history.py +265 -0
  105. package/python/vendor/baostock/security/sectorinfo.py +1024 -0
  106. package/python/vendor/baostock/util/__init__.py +0 -0
  107. package/python/vendor/baostock/util/socketutil.py +97 -0
  108. package/python/vendor/baostock/util/stringutil.py +83 -0
  109. package/python/vendor/et_xmlfile/LICENSE +23 -0
  110. package/python/vendor/et_xmlfile/LICENSE.python +298 -0
  111. package/python/vendor/et_xmlfile/__init__.py +8 -0
  112. package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
  113. package/python/vendor/et_xmlfile/xmlfile.py +158 -0
  114. package/python/vendor/openpyxl/LICENSE +23 -0
  115. package/python/vendor/openpyxl/__init__.py +19 -0
  116. package/python/vendor/openpyxl/_constants.py +13 -0
  117. package/python/vendor/openpyxl/cell/__init__.py +4 -0
  118. package/python/vendor/openpyxl/cell/_writer.py +136 -0
  119. package/python/vendor/openpyxl/cell/cell.py +332 -0
  120. package/python/vendor/openpyxl/cell/read_only.py +136 -0
  121. package/python/vendor/openpyxl/cell/rich_text.py +202 -0
  122. package/python/vendor/openpyxl/cell/text.py +184 -0
  123. package/python/vendor/openpyxl/chart/_3d.py +105 -0
  124. package/python/vendor/openpyxl/chart/__init__.py +19 -0
  125. package/python/vendor/openpyxl/chart/_chart.py +199 -0
  126. package/python/vendor/openpyxl/chart/area_chart.py +106 -0
  127. package/python/vendor/openpyxl/chart/axis.py +401 -0
  128. package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
  129. package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
  130. package/python/vendor/openpyxl/chart/chartspace.py +195 -0
  131. package/python/vendor/openpyxl/chart/data_source.py +246 -0
  132. package/python/vendor/openpyxl/chart/descriptors.py +43 -0
  133. package/python/vendor/openpyxl/chart/error_bar.py +62 -0
  134. package/python/vendor/openpyxl/chart/label.py +127 -0
  135. package/python/vendor/openpyxl/chart/layout.py +74 -0
  136. package/python/vendor/openpyxl/chart/legend.py +75 -0
  137. package/python/vendor/openpyxl/chart/line_chart.py +129 -0
  138. package/python/vendor/openpyxl/chart/marker.py +90 -0
  139. package/python/vendor/openpyxl/chart/picture.py +35 -0
  140. package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
  141. package/python/vendor/openpyxl/chart/pivot.py +65 -0
  142. package/python/vendor/openpyxl/chart/plotarea.py +162 -0
  143. package/python/vendor/openpyxl/chart/print_settings.py +57 -0
  144. package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
  145. package/python/vendor/openpyxl/chart/reader.py +32 -0
  146. package/python/vendor/openpyxl/chart/reference.py +124 -0
  147. package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
  148. package/python/vendor/openpyxl/chart/series.py +197 -0
  149. package/python/vendor/openpyxl/chart/series_factory.py +41 -0
  150. package/python/vendor/openpyxl/chart/shapes.py +89 -0
  151. package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
  152. package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
  153. package/python/vendor/openpyxl/chart/text.py +78 -0
  154. package/python/vendor/openpyxl/chart/title.py +76 -0
  155. package/python/vendor/openpyxl/chart/trendline.py +98 -0
  156. package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
  157. package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
  158. package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
  159. package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
  160. package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
  161. package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
  162. package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
  163. package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
  164. package/python/vendor/openpyxl/chartsheet/views.py +51 -0
  165. package/python/vendor/openpyxl/comments/__init__.py +4 -0
  166. package/python/vendor/openpyxl/comments/author.py +21 -0
  167. package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
  168. package/python/vendor/openpyxl/comments/comments.py +62 -0
  169. package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
  170. package/python/vendor/openpyxl/compat/__init__.py +54 -0
  171. package/python/vendor/openpyxl/compat/abc.py +8 -0
  172. package/python/vendor/openpyxl/compat/numbers.py +43 -0
  173. package/python/vendor/openpyxl/compat/product.py +17 -0
  174. package/python/vendor/openpyxl/compat/singleton.py +40 -0
  175. package/python/vendor/openpyxl/compat/strings.py +25 -0
  176. package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
  177. package/python/vendor/openpyxl/descriptors/base.py +272 -0
  178. package/python/vendor/openpyxl/descriptors/container.py +41 -0
  179. package/python/vendor/openpyxl/descriptors/excel.py +112 -0
  180. package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
  181. package/python/vendor/openpyxl/descriptors/nested.py +129 -0
  182. package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
  183. package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
  184. package/python/vendor/openpyxl/descriptors/slots.py +18 -0
  185. package/python/vendor/openpyxl/drawing/__init__.py +4 -0
  186. package/python/vendor/openpyxl/drawing/colors.py +435 -0
  187. package/python/vendor/openpyxl/drawing/connector.py +144 -0
  188. package/python/vendor/openpyxl/drawing/drawing.py +92 -0
  189. package/python/vendor/openpyxl/drawing/effect.py +407 -0
  190. package/python/vendor/openpyxl/drawing/fill.py +425 -0
  191. package/python/vendor/openpyxl/drawing/geometry.py +584 -0
  192. package/python/vendor/openpyxl/drawing/graphic.py +177 -0
  193. package/python/vendor/openpyxl/drawing/image.py +65 -0
  194. package/python/vendor/openpyxl/drawing/line.py +144 -0
  195. package/python/vendor/openpyxl/drawing/picture.py +144 -0
  196. package/python/vendor/openpyxl/drawing/properties.py +174 -0
  197. package/python/vendor/openpyxl/drawing/relation.py +17 -0
  198. package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
  199. package/python/vendor/openpyxl/drawing/text.py +717 -0
  200. package/python/vendor/openpyxl/drawing/xdr.py +33 -0
  201. package/python/vendor/openpyxl/formatting/__init__.py +3 -0
  202. package/python/vendor/openpyxl/formatting/formatting.py +114 -0
  203. package/python/vendor/openpyxl/formatting/rule.py +291 -0
  204. package/python/vendor/openpyxl/formula/__init__.py +3 -0
  205. package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
  206. package/python/vendor/openpyxl/formula/translate.py +166 -0
  207. package/python/vendor/openpyxl/packaging/__init__.py +3 -0
  208. package/python/vendor/openpyxl/packaging/core.py +115 -0
  209. package/python/vendor/openpyxl/packaging/custom.py +289 -0
  210. package/python/vendor/openpyxl/packaging/extended.py +137 -0
  211. package/python/vendor/openpyxl/packaging/interface.py +56 -0
  212. package/python/vendor/openpyxl/packaging/manifest.py +194 -0
  213. package/python/vendor/openpyxl/packaging/relationship.py +158 -0
  214. package/python/vendor/openpyxl/packaging/workbook.py +185 -0
  215. package/python/vendor/openpyxl/pivot/__init__.py +1 -0
  216. package/python/vendor/openpyxl/pivot/cache.py +965 -0
  217. package/python/vendor/openpyxl/pivot/fields.py +326 -0
  218. package/python/vendor/openpyxl/pivot/record.py +111 -0
  219. package/python/vendor/openpyxl/pivot/table.py +1261 -0
  220. package/python/vendor/openpyxl/reader/__init__.py +1 -0
  221. package/python/vendor/openpyxl/reader/drawings.py +71 -0
  222. package/python/vendor/openpyxl/reader/excel.py +349 -0
  223. package/python/vendor/openpyxl/reader/strings.py +44 -0
  224. package/python/vendor/openpyxl/reader/workbook.py +133 -0
  225. package/python/vendor/openpyxl/styles/__init__.py +11 -0
  226. package/python/vendor/openpyxl/styles/alignment.py +62 -0
  227. package/python/vendor/openpyxl/styles/borders.py +103 -0
  228. package/python/vendor/openpyxl/styles/builtins.py +1397 -0
  229. package/python/vendor/openpyxl/styles/cell_style.py +206 -0
  230. package/python/vendor/openpyxl/styles/colors.py +172 -0
  231. package/python/vendor/openpyxl/styles/differential.py +95 -0
  232. package/python/vendor/openpyxl/styles/fills.py +224 -0
  233. package/python/vendor/openpyxl/styles/fonts.py +113 -0
  234. package/python/vendor/openpyxl/styles/named_styles.py +282 -0
  235. package/python/vendor/openpyxl/styles/numbers.py +200 -0
  236. package/python/vendor/openpyxl/styles/protection.py +17 -0
  237. package/python/vendor/openpyxl/styles/proxy.py +62 -0
  238. package/python/vendor/openpyxl/styles/styleable.py +151 -0
  239. package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
  240. package/python/vendor/openpyxl/styles/table.py +94 -0
  241. package/python/vendor/openpyxl/utils/__init__.py +17 -0
  242. package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
  243. package/python/vendor/openpyxl/utils/cell.py +240 -0
  244. package/python/vendor/openpyxl/utils/dataframe.py +87 -0
  245. package/python/vendor/openpyxl/utils/datetime.py +140 -0
  246. package/python/vendor/openpyxl/utils/escape.py +43 -0
  247. package/python/vendor/openpyxl/utils/exceptions.py +34 -0
  248. package/python/vendor/openpyxl/utils/formulas.py +24 -0
  249. package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
  250. package/python/vendor/openpyxl/utils/inference.py +60 -0
  251. package/python/vendor/openpyxl/utils/protection.py +22 -0
  252. package/python/vendor/openpyxl/utils/units.py +108 -0
  253. package/python/vendor/openpyxl/workbook/__init__.py +4 -0
  254. package/python/vendor/openpyxl/workbook/_writer.py +197 -0
  255. package/python/vendor/openpyxl/workbook/child.py +166 -0
  256. package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
  257. package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
  258. package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
  259. package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
  260. package/python/vendor/openpyxl/workbook/function_group.py +36 -0
  261. package/python/vendor/openpyxl/workbook/properties.py +151 -0
  262. package/python/vendor/openpyxl/workbook/protection.py +163 -0
  263. package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
  264. package/python/vendor/openpyxl/workbook/views.py +155 -0
  265. package/python/vendor/openpyxl/workbook/web.py +98 -0
  266. package/python/vendor/openpyxl/workbook/workbook.py +438 -0
  267. package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
  268. package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
  269. package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
  270. package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
  271. package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
  272. package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
  273. package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
  274. package/python/vendor/openpyxl/worksheet/controls.py +107 -0
  275. package/python/vendor/openpyxl/worksheet/copier.py +70 -0
  276. package/python/vendor/openpyxl/worksheet/custom.py +35 -0
  277. package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
  278. package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
  279. package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
  280. package/python/vendor/openpyxl/worksheet/errors.py +93 -0
  281. package/python/vendor/openpyxl/worksheet/filters.py +486 -0
  282. package/python/vendor/openpyxl/worksheet/formula.py +51 -0
  283. package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
  284. package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
  285. package/python/vendor/openpyxl/worksheet/merge.py +141 -0
  286. package/python/vendor/openpyxl/worksheet/ole.py +133 -0
  287. package/python/vendor/openpyxl/worksheet/page.py +174 -0
  288. package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
  289. package/python/vendor/openpyxl/worksheet/picture.py +8 -0
  290. package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
  291. package/python/vendor/openpyxl/worksheet/properties.py +97 -0
  292. package/python/vendor/openpyxl/worksheet/protection.py +120 -0
  293. package/python/vendor/openpyxl/worksheet/related.py +17 -0
  294. package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
  295. package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
  296. package/python/vendor/openpyxl/worksheet/table.py +385 -0
  297. package/python/vendor/openpyxl/worksheet/views.py +155 -0
  298. package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
  299. package/python/vendor/openpyxl/writer/__init__.py +1 -0
  300. package/python/vendor/openpyxl/writer/excel.py +295 -0
  301. package/python/vendor/openpyxl/writer/theme.py +291 -0
  302. package/python/vendor/openpyxl/xml/__init__.py +42 -0
  303. package/python/vendor/openpyxl/xml/constants.py +129 -0
  304. package/python/vendor/openpyxl/xml/functions.py +87 -0
  305. package/watchlist/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+
4
+ def hash_password(plaintext_password=''):
5
+ """
6
+ Create a password hash from a given string for protecting a worksheet
7
+ only. This will not work for encrypting a workbook.
8
+
9
+ This method is based on the algorithm provided by
10
+ Daniel Rentz of OpenOffice and the PEAR package
11
+ Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
12
+ See also http://blogs.msdn.com/b/ericwhite/archive/2008/02/23/the-legacy-hashing-algorithm-in-open-xml.aspx
13
+ """
14
+ password = 0x0000
15
+ for idx, char in enumerate(plaintext_password, 1):
16
+ value = ord(char) << idx
17
+ rotated_bits = value >> 15
18
+ value &= 0x7fff
19
+ password ^= (value | rotated_bits)
20
+ password ^= len(plaintext_password)
21
+ password ^= 0xCE4B
22
+ return str(hex(password)).upper()[2:]
@@ -0,0 +1,108 @@
1
+
2
+ # Copyright (c) 2010-2024 openpyxl
3
+
4
+ import math
5
+
6
+
7
+ #constants
8
+
9
+ DEFAULT_ROW_HEIGHT = 15. # Default row height measured in point size.
10
+ BASE_COL_WIDTH = 8 # in characters
11
+ DEFAULT_COLUMN_WIDTH = BASE_COL_WIDTH + 5
12
+ # = baseColumnWidth + {margin padding (2 pixels on each side, totalling 4 pixels)} + {gridline (1pixel)}
13
+
14
+
15
+ DEFAULT_LEFT_MARGIN = 0.7 # in inches, = right margin
16
+ DEFAULT_TOP_MARGIN = 0.7874 # in inches = bottom margin
17
+ DEFAULT_HEADER = 0.3 # in inches
18
+
19
+
20
+ # Conversion functions
21
+ """
22
+ From the ECMA Spec (4th Edition part 1)
23
+ Page setup: "Left Page Margin in inches" p. 1647
24
+
25
+ Docs from
26
+ http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
27
+
28
+ See also http://msdn.microsoft.com/en-us/library/dd560821(v=office.12).aspx
29
+
30
+ dxa: The main unit in OOXML is a twentieth of a point. Also called twips.
31
+ pt: point. In Excel there are 72 points to an inch
32
+ hp: half-points are used to specify font sizes. A font-size of 12pt equals 24 half points
33
+ pct: Half-points are used to specify font sizes. A font-size of 12pt equals 24 half points
34
+
35
+ EMU: English Metric Unit, EMUs are used for coordinates in vector-based
36
+ drawings and embedded pictures. One inch equates to 914400 EMUs and a
37
+ centimeter is 360000. For bitmaps the default resolution is 96 dpi (known as
38
+ PixelsPerInch in Excel). Spec p. 1122
39
+
40
+ For radial geometry Excel uses integer units of 1/60000th of a degree.
41
+ """
42
+
43
+
44
+
45
+ def inch_to_dxa(value):
46
+ """1 inch = 72 * 20 dxa"""
47
+ return int(value * 20 * 72)
48
+
49
+ def dxa_to_inch(value):
50
+ return value / 72 / 20
51
+
52
+
53
+ def dxa_to_cm(value):
54
+ return 2.54 * dxa_to_inch(value)
55
+
56
+ def cm_to_dxa(value):
57
+ emu = cm_to_EMU(value)
58
+ inch = EMU_to_inch(emu)
59
+ return inch_to_dxa(inch)
60
+
61
+
62
+ def pixels_to_EMU(value):
63
+ """1 pixel = 9525 EMUs"""
64
+ return int(value * 9525)
65
+
66
+ def EMU_to_pixels(value):
67
+ return round(value / 9525)
68
+
69
+
70
+ def cm_to_EMU(value):
71
+ """1 cm = 360000 EMUs"""
72
+ return int(value * 360000)
73
+
74
+ def EMU_to_cm(value):
75
+ return round(value / 360000, 4)
76
+
77
+
78
+ def inch_to_EMU(value):
79
+ """1 inch = 914400 EMUs"""
80
+ return int(value * 914400)
81
+
82
+ def EMU_to_inch(value):
83
+ return round(value / 914400, 4)
84
+
85
+
86
+ def pixels_to_points(value, dpi=96):
87
+ """96 dpi, 72i"""
88
+ return value * 72 / dpi
89
+
90
+
91
+ def points_to_pixels(value, dpi=96):
92
+ return int(math.ceil(value * dpi / 72))
93
+
94
+
95
+ def degrees_to_angle(value):
96
+ """1 degree = 60000 angles"""
97
+ return int(round(value * 60000))
98
+
99
+
100
+ def angle_to_degrees(value):
101
+ return round(value / 60000, 2)
102
+
103
+
104
+ def short_color(color):
105
+ """ format a color to its short size """
106
+ if len(color) > 6:
107
+ return color[2:]
108
+ return color
@@ -0,0 +1,4 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+
4
+ from .workbook import Workbook
@@ -0,0 +1,197 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """Write the workbook global settings to the archive."""
4
+
5
+ from openpyxl.utils import quote_sheetname
6
+ from openpyxl.xml.constants import (
7
+ ARC_APP,
8
+ ARC_CORE,
9
+ ARC_CUSTOM,
10
+ ARC_WORKBOOK,
11
+ PKG_REL_NS,
12
+ CUSTOMUI_NS,
13
+ ARC_ROOT_RELS,
14
+ )
15
+ from openpyxl.xml.functions import tostring, fromstring
16
+
17
+ from openpyxl.packaging.relationship import Relationship, RelationshipList
18
+ from openpyxl.workbook.defined_name import (
19
+ DefinedName,
20
+ DefinedNameList,
21
+ )
22
+ from openpyxl.workbook.external_reference import ExternalReference
23
+ from openpyxl.packaging.workbook import ChildSheet, WorkbookPackage, PivotCache
24
+ from openpyxl.workbook.properties import WorkbookProperties
25
+ from openpyxl.utils.datetime import CALENDAR_MAC_1904
26
+
27
+
28
+ def get_active_sheet(wb):
29
+ """
30
+ Return the index of the active sheet.
31
+ If the sheet set to active is hidden return the next visible sheet or None
32
+ """
33
+ visible_sheets = [idx for idx, sheet in enumerate(wb._sheets) if sheet.sheet_state == "visible"]
34
+ if not visible_sheets:
35
+ raise IndexError("At least one sheet must be visible")
36
+
37
+ idx = wb._active_sheet_index
38
+ sheet = wb.active
39
+ if sheet and sheet.sheet_state == "visible":
40
+ return idx
41
+
42
+ for idx in visible_sheets[idx:]:
43
+ wb.active = idx
44
+ return idx
45
+
46
+ return None
47
+
48
+
49
+ class WorkbookWriter:
50
+
51
+ def __init__(self, wb):
52
+ self.wb = wb
53
+ self.rels = RelationshipList()
54
+ self.package = WorkbookPackage()
55
+ self.package.workbookProtection = wb.security
56
+ self.package.calcPr = wb.calculation
57
+
58
+
59
+ def write_properties(self):
60
+
61
+ props = WorkbookProperties() # needs a mapping to the workbook for preservation
62
+ if self.wb.code_name is not None:
63
+ props.codeName = self.wb.code_name
64
+ if self.wb.excel_base_date == CALENDAR_MAC_1904:
65
+ props.date1904 = True
66
+ self.package.workbookPr = props
67
+
68
+
69
+ def write_worksheets(self):
70
+ for idx, sheet in enumerate(self.wb._sheets, 1):
71
+ sheet_node = ChildSheet(name=sheet.title, sheetId=idx, id="rId{0}".format(idx))
72
+ rel = Relationship(type=sheet._rel_type, Target=sheet.path)
73
+ self.rels.append(rel)
74
+
75
+ if not sheet.sheet_state == 'visible':
76
+ if len(self.wb._sheets) == 1:
77
+ raise ValueError("The only worksheet of a workbook cannot be hidden")
78
+ sheet_node.state = sheet.sheet_state
79
+ self.package.sheets.append(sheet_node)
80
+
81
+
82
+ def write_refs(self):
83
+ for link in self.wb._external_links:
84
+ # need to match a counter with a workbook's relations
85
+ rId = len(self.wb.rels) + 1
86
+ rel = Relationship(type=link._rel_type, Target=link.path)
87
+ self.rels.append(rel)
88
+ ext = ExternalReference(id=rel.id)
89
+ self.package.externalReferences.append(ext)
90
+
91
+
92
+ def write_names(self):
93
+ defined_names = list(self.wb.defined_names.values())
94
+
95
+ for idx, sheet in enumerate(self.wb.worksheets):
96
+ quoted = quote_sheetname(sheet.title)
97
+
98
+ # local names
99
+ if sheet.defined_names:
100
+ names = sheet.defined_names.values()
101
+ for n in names:
102
+ n.localSheetId = idx
103
+ defined_names.extend(names)
104
+
105
+ if sheet.auto_filter:
106
+ name = DefinedName(name='_FilterDatabase', localSheetId=idx, hidden=True)
107
+ name.value = f"{quoted}!{sheet.auto_filter}"
108
+ defined_names.append(name)
109
+
110
+ if sheet.print_titles:
111
+ name = DefinedName(name="Print_Titles", localSheetId=idx)
112
+ name.value = sheet.print_titles
113
+ defined_names.append(name)
114
+
115
+ if sheet.print_area:
116
+ name = DefinedName(name="Print_Area", localSheetId=idx)
117
+ name.value = sheet.print_area
118
+ defined_names.append(name)
119
+
120
+ self.package.definedNames = DefinedNameList(definedName=defined_names)
121
+
122
+
123
+ def write_pivots(self):
124
+ pivot_caches = set()
125
+ for pivot in self.wb._pivots:
126
+ if pivot.cache not in pivot_caches:
127
+ pivot_caches.add(pivot.cache)
128
+ c = PivotCache(cacheId=pivot.cacheId)
129
+ self.package.pivotCaches.append(c)
130
+ rel = Relationship(Type=pivot.cache.rel_type, Target=pivot.cache.path)
131
+ self.rels.append(rel)
132
+ c.id = rel.id
133
+ #self.wb._pivots = [] # reset
134
+
135
+
136
+ def write_views(self):
137
+ active = get_active_sheet(self.wb)
138
+ if self.wb.views:
139
+ self.wb.views[0].activeTab = active
140
+ self.package.bookViews = self.wb.views
141
+
142
+
143
+ def write(self):
144
+ """Write the core workbook xml."""
145
+
146
+ self.write_properties()
147
+ self.write_worksheets()
148
+ self.write_names()
149
+ self.write_pivots()
150
+ self.write_views()
151
+ self.write_refs()
152
+
153
+ return tostring(self.package.to_tree())
154
+
155
+
156
+ def write_rels(self):
157
+ """Write the workbook relationships xml."""
158
+
159
+ styles = Relationship(type='styles', Target='styles.xml')
160
+ self.rels.append(styles)
161
+
162
+ theme = Relationship(type='theme', Target='theme/theme1.xml')
163
+ self.rels.append(theme)
164
+
165
+ if self.wb.vba_archive:
166
+ vba = Relationship(type='', Target='vbaProject.bin')
167
+ vba.Type ='http://schemas.microsoft.com/office/2006/relationships/vbaProject'
168
+ self.rels.append(vba)
169
+
170
+ return tostring(self.rels.to_tree())
171
+
172
+
173
+ def write_root_rels(self):
174
+ """Write the package relationships"""
175
+
176
+ rels = RelationshipList()
177
+
178
+ rel = Relationship(type="officeDocument", Target=ARC_WORKBOOK)
179
+ rels.append(rel)
180
+ rel = Relationship(Type=f"{PKG_REL_NS}/metadata/core-properties", Target=ARC_CORE)
181
+ rels.append(rel)
182
+
183
+ rel = Relationship(type="extended-properties", Target=ARC_APP)
184
+ rels.append(rel)
185
+
186
+ if len(self.wb.custom_doc_props) >= 1:
187
+ rel = Relationship(type="custom-properties", Target=ARC_CUSTOM)
188
+ rels.append(rel)
189
+
190
+ if self.wb.vba_archive is not None:
191
+ # See if there was a customUI relation and reuse it
192
+ xml = fromstring(self.wb.vba_archive.read(ARC_ROOT_RELS))
193
+ root_rels = RelationshipList.from_tree(xml)
194
+ for rel in root_rels.find(CUSTOMUI_NS):
195
+ rels.append(rel)
196
+
197
+ return tostring(rels.to_tree())
@@ -0,0 +1,166 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ import re
4
+ import warnings
5
+
6
+ from openpyxl.worksheet.header_footer import HeaderFooter
7
+
8
+ """
9
+ Base class for worksheets, chartsheets, etc. that can be added to workbooks
10
+ """
11
+
12
+ INVALID_TITLE_REGEX = re.compile(r'[\\*?:/\[\]]')
13
+
14
+
15
+ def avoid_duplicate_name(names, value):
16
+ """
17
+ Naive check to see whether name already exists.
18
+ If name does exist suggest a name using an incrementer
19
+ Duplicates are case insensitive
20
+ """
21
+ # Check for an absolute match in which case we need to find an alternative
22
+ match = [n for n in names if n.lower() == value.lower()]
23
+ if match:
24
+ names = u",".join(names)
25
+ sheet_title_regex = re.compile(f'(?P<title>{re.escape(value)})(?P<count>\\d*),?', re.I)
26
+ matches = sheet_title_regex.findall(names)
27
+ if matches:
28
+ # use name, but append with the next highest integer
29
+ counts = [int(idx) for (t, idx) in matches if idx.isdigit()]
30
+ highest = 0
31
+ if counts:
32
+ highest = max(counts)
33
+ value = u"{0}{1}".format(value, highest + 1)
34
+ return value
35
+
36
+
37
+ class _WorkbookChild:
38
+
39
+ __title = ""
40
+ _id = None
41
+ _path = "{0}"
42
+ _parent = None
43
+ _default_title = "Sheet"
44
+
45
+ def __init__(self, parent=None, title=None):
46
+ self._parent = parent
47
+ self.title = title or self._default_title
48
+ self.HeaderFooter = HeaderFooter()
49
+
50
+
51
+ def __repr__(self):
52
+ return '<{0} "{1}">'.format(self.__class__.__name__, self.title)
53
+
54
+
55
+ @property
56
+ def parent(self):
57
+ return self._parent
58
+
59
+
60
+ @property
61
+ def encoding(self):
62
+ return self._parent.encoding
63
+
64
+
65
+ @property
66
+ def title(self):
67
+ return self.__title
68
+
69
+
70
+ @title.setter
71
+ def title(self, value):
72
+ """
73
+ Set a sheet title, ensuring it is valid.
74
+ Limited to 31 characters, no special characters.
75
+ Duplicate titles will be incremented numerically
76
+ """
77
+ if not self._parent:
78
+ return
79
+
80
+ if not value:
81
+ raise ValueError("Title must have at least one character")
82
+
83
+ if hasattr(value, "decode"):
84
+ if not isinstance(value, str):
85
+ try:
86
+ value = value.decode("ascii")
87
+ except UnicodeDecodeError:
88
+ raise ValueError("Worksheet titles must be str")
89
+
90
+ m = INVALID_TITLE_REGEX.search(value)
91
+ if m:
92
+ msg = "Invalid character {0} found in sheet title".format(m.group(0))
93
+ raise ValueError(msg)
94
+
95
+ if self.title is not None and self.title != value:
96
+ value = avoid_duplicate_name(self.parent.sheetnames, value)
97
+
98
+ if len(value) > 31:
99
+ warnings.warn("Title is more than 31 characters. Some applications may not be able to read the file")
100
+
101
+ self.__title = value
102
+
103
+
104
+ @property
105
+ def oddHeader(self):
106
+ return self.HeaderFooter.oddHeader
107
+
108
+
109
+ @oddHeader.setter
110
+ def oddHeader(self, value):
111
+ self.HeaderFooter.oddHeader = value
112
+
113
+
114
+ @property
115
+ def oddFooter(self):
116
+ return self.HeaderFooter.oddFooter
117
+
118
+
119
+ @oddFooter.setter
120
+ def oddFooter(self, value):
121
+ self.HeaderFooter.oddFooter = value
122
+
123
+
124
+ @property
125
+ def evenHeader(self):
126
+ return self.HeaderFooter.evenHeader
127
+
128
+
129
+ @evenHeader.setter
130
+ def evenHeader(self, value):
131
+ self.HeaderFooter.evenHeader = value
132
+
133
+
134
+ @property
135
+ def evenFooter(self):
136
+ return self.HeaderFooter.evenFooter
137
+
138
+
139
+ @evenFooter.setter
140
+ def evenFooter(self, value):
141
+ self.HeaderFooter.evenFooter = value
142
+
143
+
144
+ @property
145
+ def firstHeader(self):
146
+ return self.HeaderFooter.firstHeader
147
+
148
+
149
+ @firstHeader.setter
150
+ def firstHeader(self, value):
151
+ self.HeaderFooter.firstHeader = value
152
+
153
+
154
+ @property
155
+ def firstFooter(self):
156
+ return self.HeaderFooter.firstFooter
157
+
158
+
159
+ @firstFooter.setter
160
+ def firstFooter(self, value):
161
+ self.HeaderFooter.firstFooter = value
162
+
163
+
164
+ @property
165
+ def path(self):
166
+ return self._path.format(self._id)
@@ -0,0 +1,189 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ from collections import defaultdict
4
+ import re
5
+
6
+ from openpyxl.descriptors.serialisable import Serialisable
7
+ from openpyxl.descriptors import (
8
+ Alias,
9
+ String,
10
+ Integer,
11
+ Bool,
12
+ Sequence,
13
+ Descriptor,
14
+ )
15
+ from openpyxl.compat import safe_string
16
+ from openpyxl.formula import Tokenizer
17
+ from openpyxl.utils.cell import SHEETRANGE_RE
18
+
19
+ RESERVED = frozenset(["Print_Area", "Print_Titles", "Criteria",
20
+ "_FilterDatabase", "Extract", "Consolidate_Area",
21
+ "Sheet_Title"])
22
+
23
+ _names = "|".join(RESERVED)
24
+ RESERVED_REGEX = re.compile(r"^_xlnm\.(?P<name>{0})".format(_names))
25
+
26
+
27
+ class DefinedName(Serialisable):
28
+
29
+ tagname = "definedName"
30
+
31
+ name = String() # unique per workbook/worksheet
32
+ comment = String(allow_none=True)
33
+ customMenu = String(allow_none=True)
34
+ description = String(allow_none=True)
35
+ help = String(allow_none=True)
36
+ statusBar = String(allow_none=True)
37
+ localSheetId = Integer(allow_none=True)
38
+ hidden = Bool(allow_none=True)
39
+ function = Bool(allow_none=True)
40
+ vbProcedure = Bool(allow_none=True)
41
+ xlm = Bool(allow_none=True)
42
+ functionGroupId = Integer(allow_none=True)
43
+ shortcutKey = String(allow_none=True)
44
+ publishToServer = Bool(allow_none=True)
45
+ workbookParameter = Bool(allow_none=True)
46
+ attr_text = Descriptor()
47
+ value = Alias("attr_text")
48
+
49
+
50
+ def __init__(self,
51
+ name=None,
52
+ comment=None,
53
+ customMenu=None,
54
+ description=None,
55
+ help=None,
56
+ statusBar=None,
57
+ localSheetId=None,
58
+ hidden=None,
59
+ function=None,
60
+ vbProcedure=None,
61
+ xlm=None,
62
+ functionGroupId=None,
63
+ shortcutKey=None,
64
+ publishToServer=None,
65
+ workbookParameter=None,
66
+ attr_text=None
67
+ ):
68
+ self.name = name
69
+ self.comment = comment
70
+ self.customMenu = customMenu
71
+ self.description = description
72
+ self.help = help
73
+ self.statusBar = statusBar
74
+ self.localSheetId = localSheetId
75
+ self.hidden = hidden
76
+ self.function = function
77
+ self.vbProcedure = vbProcedure
78
+ self.xlm = xlm
79
+ self.functionGroupId = functionGroupId
80
+ self.shortcutKey = shortcutKey
81
+ self.publishToServer = publishToServer
82
+ self.workbookParameter = workbookParameter
83
+ self.attr_text = attr_text
84
+
85
+
86
+ @property
87
+ def type(self):
88
+ tok = Tokenizer("=" + self.value)
89
+ parsed = tok.items[0]
90
+ if parsed.type == "OPERAND":
91
+ return parsed.subtype
92
+ return parsed.type
93
+
94
+
95
+ @property
96
+ def destinations(self):
97
+ if self.type == "RANGE":
98
+ tok = Tokenizer("=" + self.value)
99
+ for part in tok.items:
100
+ if part.subtype == "RANGE":
101
+ m = SHEETRANGE_RE.match(part.value)
102
+ sheetname = m.group('notquoted') or m.group('quoted')
103
+ yield sheetname, m.group('cells')
104
+
105
+
106
+ @property
107
+ def is_reserved(self):
108
+ m = RESERVED_REGEX.match(self.name)
109
+ if m:
110
+ return m.group("name")
111
+
112
+
113
+ @property
114
+ def is_external(self):
115
+ return re.compile(r"^\[\d+\].*").match(self.value) is not None
116
+
117
+
118
+ def __iter__(self):
119
+ for key in self.__attrs__:
120
+ if key == "attr_text":
121
+ continue
122
+ v = getattr(self, key)
123
+ if v is not None:
124
+ if v in RESERVED:
125
+ v = "_xlnm." + v
126
+ yield key, safe_string(v)
127
+
128
+
129
+ class DefinedNameDict(dict):
130
+
131
+ """
132
+ Utility class for storing defined names.
133
+ Allows access by name and separation of global and scoped names
134
+ """
135
+
136
+ def __setitem__(self, key, value):
137
+ if not isinstance(value, DefinedName):
138
+ raise TypeError("Value must be a an instance of DefinedName")
139
+ elif value.name != key:
140
+ raise ValueError("Key must be the same as the name")
141
+ super().__setitem__(key, value)
142
+
143
+
144
+ def add(self, value):
145
+ """
146
+ Add names without worrying about key and name matching.
147
+ """
148
+ self[value.name] = value
149
+
150
+
151
+ class DefinedNameList(Serialisable):
152
+
153
+ tagname = "definedNames"
154
+
155
+ definedName = Sequence(expected_type=DefinedName)
156
+
157
+
158
+ def __init__(self, definedName=()):
159
+ self.definedName = definedName
160
+
161
+
162
+ def by_sheet(self):
163
+ """
164
+ Break names down into sheet locals and globals
165
+ """
166
+ names = defaultdict(DefinedNameDict)
167
+ for defn in self.definedName:
168
+ if defn.localSheetId is None:
169
+ if defn.name in ("_xlnm.Print_Titles", "_xlnm.Print_Area", "_xlnm._FilterDatabase"):
170
+ continue
171
+ names["global"][defn.name] = defn
172
+ else:
173
+ sheet = int(defn.localSheetId)
174
+ names[sheet][defn.name] = defn
175
+ return names
176
+
177
+
178
+ def _duplicate(self, defn):
179
+ """
180
+ Check for whether DefinedName with the same name and scope already
181
+ exists
182
+ """
183
+ for d in self.definedName:
184
+ if d.name == defn.name and d.localSheetId == defn.localSheetId:
185
+ return True
186
+
187
+
188
+ def __len__(self):
189
+ return len(self.definedName)
@@ -0,0 +1,3 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ from .external import ExternalLink