@v587d/capital-generation 2.28.0 → 2.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +5 -4
  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/tools.js +7 -7
  11. package/lib/host-version.d.ts +9 -0
  12. package/lib/host-version.js +57 -0
  13. package/lib/python-runtime/errors.d.ts +1 -1
  14. package/lib/python-runtime/errors.js +2 -0
  15. package/lib/python-runtime/manager.d.ts +28 -1
  16. package/lib/python-runtime/manager.js +141 -5
  17. package/lib/python-runtime/probe.d.ts +24 -0
  18. package/lib/python-runtime/probe.js +66 -50
  19. package/lib/runtime-entry.js +8 -0
  20. package/lib/sources/csindex-http.d.ts +4 -0
  21. package/lib/sources/csindex-http.js +233 -0
  22. package/lib/sources/eastmoney-http.js +1504 -1
  23. package/lib/sources/fuyao-rest.js +168 -8
  24. package/lib/sources/official-http.d.ts +4 -0
  25. package/lib/sources/official-http.js +477 -0
  26. package/lib/sources/python-remote.d.ts +25 -0
  27. package/lib/sources/python-remote.js +461 -0
  28. package/lib/sources/sina-http.d.ts +2 -0
  29. package/lib/sources/sina-http.js +484 -0
  30. package/lib/sources/tencent-http.js +23 -8
  31. package/lib/sources/ths-http.d.ts +2 -0
  32. package/lib/sources/ths-http.js +514 -0
  33. package/lib/time/tools.js +19 -0
  34. package/lib/web-retriever/local-fetch.d.ts +1 -1
  35. package/lib/web-retriever/local-fetch.js +1 -1
  36. package/lib/web-retriever/sources.d.ts +7 -0
  37. package/lib/web-retriever/sources.js +46 -21
  38. package/lib/web-retriever/throttle.d.ts +8 -0
  39. package/lib/web-retriever/throttle.js +13 -0
  40. package/lib/web-retriever/tools.js +1 -1
  41. package/lib/web-retriever/wind-client.d.ts +1 -1
  42. package/lib/web-retriever/wind-client.js +1 -1
  43. package/package.json +6 -3
  44. package/preset/capital-generation/agent.patch.yml +7 -5
  45. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
  46. package/python/scripts/baostock_stock_basic.py +129 -0
  47. package/python/scripts/baostock_valuation_history.py +141 -0
  48. package/python/scripts/pbc_social_financing.py +291 -0
  49. package/python/vendor/baostock/LICENSE +19 -0
  50. package/python/vendor/baostock/__init__.py +42 -0
  51. package/python/vendor/baostock/common/__init__.py +0 -0
  52. package/python/vendor/baostock/common/contants.py +189 -0
  53. package/python/vendor/baostock/common/context.py +4 -0
  54. package/python/vendor/baostock/corpreport/__init__.py +0 -0
  55. package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
  56. package/python/vendor/baostock/data/__init__.py +0 -0
  57. package/python/vendor/baostock/data/messageheader.py +17 -0
  58. package/python/vendor/baostock/data/msg.py +21 -0
  59. package/python/vendor/baostock/data/resultset.py +200 -0
  60. package/python/vendor/baostock/demo/__init__.py +0 -0
  61. package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
  62. package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
  63. package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
  64. package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
  65. package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
  66. package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
  67. package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
  68. package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
  69. package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
  70. package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
  71. package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
  72. package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
  73. package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
  74. package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
  75. package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
  76. package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
  77. package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
  78. package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
  79. package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
  80. package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
  81. package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
  82. package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
  83. package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
  84. package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
  85. package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
  86. package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
  87. package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
  88. package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
  89. package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
  90. package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
  91. package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
  92. package/python/vendor/baostock/evaluation/__init__.py +0 -0
  93. package/python/vendor/baostock/evaluation/season_index.py +758 -0
  94. package/python/vendor/baostock/login/__init__.py +0 -0
  95. package/python/vendor/baostock/login/loginout.py +230 -0
  96. package/python/vendor/baostock/macroscopic/__init__.py +0 -0
  97. package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
  98. package/python/vendor/baostock/metadata/__init__.py +0 -0
  99. package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
  100. package/python/vendor/baostock/security/__init__.py +0 -0
  101. package/python/vendor/baostock/security/history.py +265 -0
  102. package/python/vendor/baostock/security/sectorinfo.py +1024 -0
  103. package/python/vendor/baostock/util/__init__.py +0 -0
  104. package/python/vendor/baostock/util/socketutil.py +97 -0
  105. package/python/vendor/baostock/util/stringutil.py +83 -0
  106. package/python/vendor/et_xmlfile/LICENSE +23 -0
  107. package/python/vendor/et_xmlfile/LICENSE.python +298 -0
  108. package/python/vendor/et_xmlfile/__init__.py +8 -0
  109. package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
  110. package/python/vendor/et_xmlfile/xmlfile.py +158 -0
  111. package/python/vendor/openpyxl/LICENSE +23 -0
  112. package/python/vendor/openpyxl/__init__.py +19 -0
  113. package/python/vendor/openpyxl/_constants.py +13 -0
  114. package/python/vendor/openpyxl/cell/__init__.py +4 -0
  115. package/python/vendor/openpyxl/cell/_writer.py +136 -0
  116. package/python/vendor/openpyxl/cell/cell.py +332 -0
  117. package/python/vendor/openpyxl/cell/read_only.py +136 -0
  118. package/python/vendor/openpyxl/cell/rich_text.py +202 -0
  119. package/python/vendor/openpyxl/cell/text.py +184 -0
  120. package/python/vendor/openpyxl/chart/_3d.py +105 -0
  121. package/python/vendor/openpyxl/chart/__init__.py +19 -0
  122. package/python/vendor/openpyxl/chart/_chart.py +199 -0
  123. package/python/vendor/openpyxl/chart/area_chart.py +106 -0
  124. package/python/vendor/openpyxl/chart/axis.py +401 -0
  125. package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
  126. package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
  127. package/python/vendor/openpyxl/chart/chartspace.py +195 -0
  128. package/python/vendor/openpyxl/chart/data_source.py +246 -0
  129. package/python/vendor/openpyxl/chart/descriptors.py +43 -0
  130. package/python/vendor/openpyxl/chart/error_bar.py +62 -0
  131. package/python/vendor/openpyxl/chart/label.py +127 -0
  132. package/python/vendor/openpyxl/chart/layout.py +74 -0
  133. package/python/vendor/openpyxl/chart/legend.py +75 -0
  134. package/python/vendor/openpyxl/chart/line_chart.py +129 -0
  135. package/python/vendor/openpyxl/chart/marker.py +90 -0
  136. package/python/vendor/openpyxl/chart/picture.py +35 -0
  137. package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
  138. package/python/vendor/openpyxl/chart/pivot.py +65 -0
  139. package/python/vendor/openpyxl/chart/plotarea.py +162 -0
  140. package/python/vendor/openpyxl/chart/print_settings.py +57 -0
  141. package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
  142. package/python/vendor/openpyxl/chart/reader.py +32 -0
  143. package/python/vendor/openpyxl/chart/reference.py +124 -0
  144. package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
  145. package/python/vendor/openpyxl/chart/series.py +197 -0
  146. package/python/vendor/openpyxl/chart/series_factory.py +41 -0
  147. package/python/vendor/openpyxl/chart/shapes.py +89 -0
  148. package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
  149. package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
  150. package/python/vendor/openpyxl/chart/text.py +78 -0
  151. package/python/vendor/openpyxl/chart/title.py +76 -0
  152. package/python/vendor/openpyxl/chart/trendline.py +98 -0
  153. package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
  154. package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
  155. package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
  156. package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
  157. package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
  158. package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
  159. package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
  160. package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
  161. package/python/vendor/openpyxl/chartsheet/views.py +51 -0
  162. package/python/vendor/openpyxl/comments/__init__.py +4 -0
  163. package/python/vendor/openpyxl/comments/author.py +21 -0
  164. package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
  165. package/python/vendor/openpyxl/comments/comments.py +62 -0
  166. package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
  167. package/python/vendor/openpyxl/compat/__init__.py +54 -0
  168. package/python/vendor/openpyxl/compat/abc.py +8 -0
  169. package/python/vendor/openpyxl/compat/numbers.py +43 -0
  170. package/python/vendor/openpyxl/compat/product.py +17 -0
  171. package/python/vendor/openpyxl/compat/singleton.py +40 -0
  172. package/python/vendor/openpyxl/compat/strings.py +25 -0
  173. package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
  174. package/python/vendor/openpyxl/descriptors/base.py +272 -0
  175. package/python/vendor/openpyxl/descriptors/container.py +41 -0
  176. package/python/vendor/openpyxl/descriptors/excel.py +112 -0
  177. package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
  178. package/python/vendor/openpyxl/descriptors/nested.py +129 -0
  179. package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
  180. package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
  181. package/python/vendor/openpyxl/descriptors/slots.py +18 -0
  182. package/python/vendor/openpyxl/drawing/__init__.py +4 -0
  183. package/python/vendor/openpyxl/drawing/colors.py +435 -0
  184. package/python/vendor/openpyxl/drawing/connector.py +144 -0
  185. package/python/vendor/openpyxl/drawing/drawing.py +92 -0
  186. package/python/vendor/openpyxl/drawing/effect.py +407 -0
  187. package/python/vendor/openpyxl/drawing/fill.py +425 -0
  188. package/python/vendor/openpyxl/drawing/geometry.py +584 -0
  189. package/python/vendor/openpyxl/drawing/graphic.py +177 -0
  190. package/python/vendor/openpyxl/drawing/image.py +65 -0
  191. package/python/vendor/openpyxl/drawing/line.py +144 -0
  192. package/python/vendor/openpyxl/drawing/picture.py +144 -0
  193. package/python/vendor/openpyxl/drawing/properties.py +174 -0
  194. package/python/vendor/openpyxl/drawing/relation.py +17 -0
  195. package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
  196. package/python/vendor/openpyxl/drawing/text.py +717 -0
  197. package/python/vendor/openpyxl/drawing/xdr.py +33 -0
  198. package/python/vendor/openpyxl/formatting/__init__.py +3 -0
  199. package/python/vendor/openpyxl/formatting/formatting.py +114 -0
  200. package/python/vendor/openpyxl/formatting/rule.py +291 -0
  201. package/python/vendor/openpyxl/formula/__init__.py +3 -0
  202. package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
  203. package/python/vendor/openpyxl/formula/translate.py +166 -0
  204. package/python/vendor/openpyxl/packaging/__init__.py +3 -0
  205. package/python/vendor/openpyxl/packaging/core.py +115 -0
  206. package/python/vendor/openpyxl/packaging/custom.py +289 -0
  207. package/python/vendor/openpyxl/packaging/extended.py +137 -0
  208. package/python/vendor/openpyxl/packaging/interface.py +56 -0
  209. package/python/vendor/openpyxl/packaging/manifest.py +194 -0
  210. package/python/vendor/openpyxl/packaging/relationship.py +158 -0
  211. package/python/vendor/openpyxl/packaging/workbook.py +185 -0
  212. package/python/vendor/openpyxl/pivot/__init__.py +1 -0
  213. package/python/vendor/openpyxl/pivot/cache.py +965 -0
  214. package/python/vendor/openpyxl/pivot/fields.py +326 -0
  215. package/python/vendor/openpyxl/pivot/record.py +111 -0
  216. package/python/vendor/openpyxl/pivot/table.py +1261 -0
  217. package/python/vendor/openpyxl/reader/__init__.py +1 -0
  218. package/python/vendor/openpyxl/reader/drawings.py +71 -0
  219. package/python/vendor/openpyxl/reader/excel.py +349 -0
  220. package/python/vendor/openpyxl/reader/strings.py +44 -0
  221. package/python/vendor/openpyxl/reader/workbook.py +133 -0
  222. package/python/vendor/openpyxl/styles/__init__.py +11 -0
  223. package/python/vendor/openpyxl/styles/alignment.py +62 -0
  224. package/python/vendor/openpyxl/styles/borders.py +103 -0
  225. package/python/vendor/openpyxl/styles/builtins.py +1397 -0
  226. package/python/vendor/openpyxl/styles/cell_style.py +206 -0
  227. package/python/vendor/openpyxl/styles/colors.py +172 -0
  228. package/python/vendor/openpyxl/styles/differential.py +95 -0
  229. package/python/vendor/openpyxl/styles/fills.py +224 -0
  230. package/python/vendor/openpyxl/styles/fonts.py +113 -0
  231. package/python/vendor/openpyxl/styles/named_styles.py +282 -0
  232. package/python/vendor/openpyxl/styles/numbers.py +200 -0
  233. package/python/vendor/openpyxl/styles/protection.py +17 -0
  234. package/python/vendor/openpyxl/styles/proxy.py +62 -0
  235. package/python/vendor/openpyxl/styles/styleable.py +151 -0
  236. package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
  237. package/python/vendor/openpyxl/styles/table.py +94 -0
  238. package/python/vendor/openpyxl/utils/__init__.py +17 -0
  239. package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
  240. package/python/vendor/openpyxl/utils/cell.py +240 -0
  241. package/python/vendor/openpyxl/utils/dataframe.py +87 -0
  242. package/python/vendor/openpyxl/utils/datetime.py +140 -0
  243. package/python/vendor/openpyxl/utils/escape.py +43 -0
  244. package/python/vendor/openpyxl/utils/exceptions.py +34 -0
  245. package/python/vendor/openpyxl/utils/formulas.py +24 -0
  246. package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
  247. package/python/vendor/openpyxl/utils/inference.py +60 -0
  248. package/python/vendor/openpyxl/utils/protection.py +22 -0
  249. package/python/vendor/openpyxl/utils/units.py +108 -0
  250. package/python/vendor/openpyxl/workbook/__init__.py +4 -0
  251. package/python/vendor/openpyxl/workbook/_writer.py +197 -0
  252. package/python/vendor/openpyxl/workbook/child.py +166 -0
  253. package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
  254. package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
  255. package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
  256. package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
  257. package/python/vendor/openpyxl/workbook/function_group.py +36 -0
  258. package/python/vendor/openpyxl/workbook/properties.py +151 -0
  259. package/python/vendor/openpyxl/workbook/protection.py +163 -0
  260. package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
  261. package/python/vendor/openpyxl/workbook/views.py +155 -0
  262. package/python/vendor/openpyxl/workbook/web.py +98 -0
  263. package/python/vendor/openpyxl/workbook/workbook.py +438 -0
  264. package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
  265. package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
  266. package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
  267. package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
  268. package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
  269. package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
  270. package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
  271. package/python/vendor/openpyxl/worksheet/controls.py +107 -0
  272. package/python/vendor/openpyxl/worksheet/copier.py +70 -0
  273. package/python/vendor/openpyxl/worksheet/custom.py +35 -0
  274. package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
  275. package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
  276. package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
  277. package/python/vendor/openpyxl/worksheet/errors.py +93 -0
  278. package/python/vendor/openpyxl/worksheet/filters.py +486 -0
  279. package/python/vendor/openpyxl/worksheet/formula.py +51 -0
  280. package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
  281. package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
  282. package/python/vendor/openpyxl/worksheet/merge.py +141 -0
  283. package/python/vendor/openpyxl/worksheet/ole.py +133 -0
  284. package/python/vendor/openpyxl/worksheet/page.py +174 -0
  285. package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
  286. package/python/vendor/openpyxl/worksheet/picture.py +8 -0
  287. package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
  288. package/python/vendor/openpyxl/worksheet/properties.py +97 -0
  289. package/python/vendor/openpyxl/worksheet/protection.py +120 -0
  290. package/python/vendor/openpyxl/worksheet/related.py +17 -0
  291. package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
  292. package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
  293. package/python/vendor/openpyxl/worksheet/table.py +385 -0
  294. package/python/vendor/openpyxl/worksheet/views.py +155 -0
  295. package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
  296. package/python/vendor/openpyxl/writer/__init__.py +1 -0
  297. package/python/vendor/openpyxl/writer/excel.py +295 -0
  298. package/python/vendor/openpyxl/writer/theme.py +291 -0
  299. package/python/vendor/openpyxl/xml/__init__.py +42 -0
  300. package/python/vendor/openpyxl/xml/constants.py +129 -0
  301. package/python/vendor/openpyxl/xml/functions.py +87 -0
  302. package/watchlist/package.json +1 -1
@@ -0,0 +1,190 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """ Read worksheets on-demand
4
+ """
5
+
6
+ from .worksheet import Worksheet
7
+ from openpyxl.cell.read_only import ReadOnlyCell, EMPTY_CELL
8
+ from openpyxl.utils import get_column_letter
9
+
10
+ from ._reader import WorkSheetParser
11
+ from openpyxl.workbook.defined_name import DefinedNameDict
12
+
13
+
14
+ def read_dimension(source):
15
+ parser = WorkSheetParser(source, [])
16
+ return parser.parse_dimensions()
17
+
18
+
19
+ class ReadOnlyWorksheet:
20
+
21
+ _min_column = 1
22
+ _min_row = 1
23
+ _max_column = _max_row = None
24
+
25
+ # from Standard Worksheet
26
+ # Methods from Worksheet
27
+ cell = Worksheet.cell
28
+ iter_rows = Worksheet.iter_rows
29
+ values = Worksheet.values
30
+ rows = Worksheet.rows
31
+ __getitem__ = Worksheet.__getitem__
32
+ __iter__ = Worksheet.__iter__
33
+
34
+
35
+ def __init__(self, parent_workbook, title, worksheet_path, shared_strings):
36
+ self.parent = parent_workbook
37
+ self.title = title
38
+ self.sheet_state = 'visible'
39
+ self._current_row = None
40
+ self._worksheet_path = worksheet_path
41
+ self._shared_strings = shared_strings
42
+ self._get_size()
43
+ self.defined_names = DefinedNameDict()
44
+
45
+
46
+ def _get_size(self):
47
+ src = self._get_source()
48
+ parser = WorkSheetParser(src, [])
49
+ dimensions = parser.parse_dimensions()
50
+ src.close()
51
+ if dimensions is not None:
52
+ self._min_column, self._min_row, self._max_column, self._max_row = dimensions
53
+
54
+
55
+ def _get_source(self):
56
+ """Parse xml source on demand, must close after use"""
57
+ return self.parent._archive.open(self._worksheet_path)
58
+
59
+
60
+ def _cells_by_row(self, min_col, min_row, max_col, max_row, values_only=False):
61
+ """
62
+ The source worksheet file may have columns or rows missing.
63
+ Missing cells will be created.
64
+ """
65
+ filler = EMPTY_CELL
66
+ if values_only:
67
+ filler = None
68
+
69
+ max_col = max_col or self.max_column
70
+ max_row = max_row or self.max_row
71
+ empty_row = []
72
+ if max_col is not None:
73
+ empty_row = (filler,) * (max_col + 1 - min_col)
74
+
75
+ counter = min_row
76
+ idx = 1
77
+ with self._get_source() as src:
78
+ parser = WorkSheetParser(src,
79
+ self._shared_strings,
80
+ data_only=self.parent.data_only,
81
+ epoch=self.parent.epoch,
82
+ date_formats=self.parent._date_formats,
83
+ timedelta_formats=self.parent._timedelta_formats)
84
+
85
+ for idx, row in parser.parse():
86
+ if max_row is not None and idx > max_row:
87
+ break
88
+
89
+ # some rows are missing
90
+ for _ in range(counter, idx):
91
+ counter += 1
92
+ yield empty_row
93
+
94
+ # return cells from a row
95
+ if counter <= idx:
96
+ row = self._get_row(row, min_col, max_col, values_only)
97
+ counter += 1
98
+ yield row
99
+
100
+ if max_row is not None and max_row < idx:
101
+ for _ in range(counter, max_row+1):
102
+ yield empty_row
103
+
104
+
105
+ def _get_row(self, row, min_col=1, max_col=None, values_only=False):
106
+ """
107
+ Make sure a row contains always the same number of cells or values
108
+ """
109
+ if not row and not max_col: # in case someone wants to force rows where there aren't any
110
+ return ()
111
+
112
+ max_col = max_col or row[-1]['column']
113
+ row_width = max_col + 1 - min_col
114
+
115
+ new_row = [EMPTY_CELL] * row_width
116
+ if values_only:
117
+ new_row = [None] * row_width
118
+
119
+ for cell in row:
120
+ counter = cell['column']
121
+ if min_col <= counter <= max_col:
122
+ idx = counter - min_col # position in list of cells returned
123
+ new_row[idx] = cell['value']
124
+ if not values_only:
125
+ new_row[idx] = ReadOnlyCell(self, **cell)
126
+
127
+ return tuple(new_row)
128
+
129
+
130
+ def _get_cell(self, row, column):
131
+ """Cells are returned by a generator which can be empty"""
132
+ for row in self._cells_by_row(column, row, column, row):
133
+ if row:
134
+ return row[0]
135
+ return EMPTY_CELL
136
+
137
+
138
+ def calculate_dimension(self, force=False):
139
+ if not all([self.max_column, self.max_row]):
140
+ if force:
141
+ self._calculate_dimension()
142
+ else:
143
+ raise ValueError("Worksheet is unsized, use calculate_dimension(force=True)")
144
+ return f"{get_column_letter(self.min_column)}{self.min_row}:{get_column_letter(self.max_column)}{self.max_row}"
145
+
146
+
147
+ def _calculate_dimension(self):
148
+ """
149
+ Loop through all the cells to get the size of a worksheet.
150
+ Do this only if it is explicitly requested.
151
+ """
152
+
153
+ max_col = 0
154
+ for r in self.rows:
155
+ if not r:
156
+ continue
157
+ cell = r[-1]
158
+ max_col = max(max_col, cell.column)
159
+
160
+ self._max_row = cell.row
161
+ self._max_column = max_col
162
+
163
+
164
+ def reset_dimensions(self):
165
+ """
166
+ Remove worksheet dimensions if these are incorrect in the worksheet source.
167
+ NB. This probably indicates a bug in the library or application that created
168
+ the workbook.
169
+ """
170
+ self._max_row = self._max_column = None
171
+
172
+
173
+ @property
174
+ def min_row(self):
175
+ return self._min_row
176
+
177
+
178
+ @property
179
+ def max_row(self):
180
+ return self._max_row
181
+
182
+
183
+ @property
184
+ def min_column(self):
185
+ return self._min_column
186
+
187
+
188
+ @property
189
+ def max_column(self):
190
+ return self._max_column
@@ -0,0 +1,472 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """Reader for a single worksheet."""
4
+ from copy import copy
5
+ from warnings import warn
6
+
7
+ # compatibility imports
8
+ from openpyxl.xml.functions import iterparse
9
+
10
+ # package imports
11
+ from openpyxl.cell import Cell, MergedCell
12
+ from openpyxl.cell.text import Text
13
+ from openpyxl.worksheet.dimensions import (
14
+ ColumnDimension,
15
+ RowDimension,
16
+ SheetFormatProperties,
17
+ )
18
+
19
+ from openpyxl.xml.constants import (
20
+ SHEET_MAIN_NS,
21
+ EXT_TYPES,
22
+ )
23
+ from openpyxl.formatting.formatting import ConditionalFormatting
24
+ from openpyxl.formula.translate import Translator
25
+ from openpyxl.utils import (
26
+ get_column_letter,
27
+ coordinate_to_tuple,
28
+ )
29
+ from openpyxl.utils.datetime import from_excel, from_ISO8601, WINDOWS_EPOCH
30
+ from openpyxl.descriptors.excel import ExtensionList
31
+ from openpyxl.cell.rich_text import CellRichText
32
+
33
+ from .formula import DataTableFormula, ArrayFormula
34
+ from .filters import AutoFilter
35
+ from .header_footer import HeaderFooter
36
+ from .hyperlink import HyperlinkList
37
+ from .merge import MergeCells
38
+ from .page import PageMargins, PrintOptions, PrintPageSetup
39
+ from .pagebreak import RowBreak, ColBreak
40
+ from .protection import SheetProtection
41
+ from .scenario import ScenarioList
42
+ from .views import SheetViewList
43
+ from .datavalidation import DataValidationList
44
+ from .table import TablePartList
45
+ from .properties import WorksheetProperties
46
+ from .dimensions import SheetDimension
47
+ from .related import Related
48
+
49
+
50
+ CELL_TAG = '{%s}c' % SHEET_MAIN_NS
51
+ VALUE_TAG = '{%s}v' % SHEET_MAIN_NS
52
+ FORMULA_TAG = '{%s}f' % SHEET_MAIN_NS
53
+ MERGE_TAG = '{%s}mergeCells' % SHEET_MAIN_NS
54
+ INLINE_STRING = "{%s}is" % SHEET_MAIN_NS
55
+ COL_TAG = '{%s}col' % SHEET_MAIN_NS
56
+ ROW_TAG = '{%s}row' % SHEET_MAIN_NS
57
+ CF_TAG = '{%s}conditionalFormatting' % SHEET_MAIN_NS
58
+ LEGACY_TAG = '{%s}legacyDrawing' % SHEET_MAIN_NS
59
+ PROT_TAG = '{%s}sheetProtection' % SHEET_MAIN_NS
60
+ EXT_TAG = "{%s}extLst" % SHEET_MAIN_NS
61
+ HYPERLINK_TAG = "{%s}hyperlinks" % SHEET_MAIN_NS
62
+ TABLE_TAG = "{%s}tableParts" % SHEET_MAIN_NS
63
+ PRINT_TAG = '{%s}printOptions' % SHEET_MAIN_NS
64
+ MARGINS_TAG = '{%s}pageMargins' % SHEET_MAIN_NS
65
+ PAGE_TAG = '{%s}pageSetup' % SHEET_MAIN_NS
66
+ HEADER_TAG = '{%s}headerFooter' % SHEET_MAIN_NS
67
+ FILTER_TAG = '{%s}autoFilter' % SHEET_MAIN_NS
68
+ VALIDATION_TAG = '{%s}dataValidations' % SHEET_MAIN_NS
69
+ PROPERTIES_TAG = '{%s}sheetPr' % SHEET_MAIN_NS
70
+ VIEWS_TAG = '{%s}sheetViews' % SHEET_MAIN_NS
71
+ FORMAT_TAG = '{%s}sheetFormatPr' % SHEET_MAIN_NS
72
+ ROW_BREAK_TAG = '{%s}rowBreaks' % SHEET_MAIN_NS
73
+ COL_BREAK_TAG = '{%s}colBreaks' % SHEET_MAIN_NS
74
+ SCENARIOS_TAG = '{%s}scenarios' % SHEET_MAIN_NS
75
+ DATA_TAG = '{%s}sheetData' % SHEET_MAIN_NS
76
+ DIMENSION_TAG = '{%s}dimension' % SHEET_MAIN_NS
77
+ CUSTOM_VIEWS_TAG = '{%s}customSheetViews' % SHEET_MAIN_NS
78
+
79
+
80
+ def _cast_number(value):
81
+ "Convert numbers as string to an int or float"
82
+ if "." in value or "E" in value or "e" in value:
83
+ return float(value)
84
+ return int(value)
85
+
86
+
87
+ def parse_richtext_string(element):
88
+ """
89
+ Parse inline string and preserve rich text formatting
90
+ """
91
+ value = CellRichText.from_tree(element) or ""
92
+ if len(value) == 1 and isinstance(value[0], str):
93
+ value = value[0]
94
+ return value
95
+
96
+
97
+ class WorkSheetParser:
98
+
99
+ def __init__(self, src, shared_strings, data_only=False,
100
+ epoch=WINDOWS_EPOCH, date_formats=set(),
101
+ timedelta_formats=set(), rich_text=False):
102
+ self.min_row = self.min_col = None
103
+ self.epoch = epoch
104
+ self.source = src
105
+ self.shared_strings = shared_strings
106
+ self.data_only = data_only
107
+ self.shared_formulae = {}
108
+ self.row_counter = self.col_counter = 0
109
+ self.tables = TablePartList()
110
+ self.date_formats = date_formats
111
+ self.timedelta_formats = timedelta_formats
112
+ self.row_dimensions = {}
113
+ self.column_dimensions = {}
114
+ self.number_formats = []
115
+ self.keep_vba = False
116
+ self.hyperlinks = HyperlinkList()
117
+ self.formatting = []
118
+ self.legacy_drawing = None
119
+ self.merged_cells = None
120
+ self.row_breaks = RowBreak()
121
+ self.col_breaks = ColBreak()
122
+ self.rich_text = rich_text
123
+
124
+
125
+ def parse(self):
126
+ dispatcher = {
127
+ COL_TAG: self.parse_column_dimensions,
128
+ PROT_TAG: self.parse_sheet_protection,
129
+ EXT_TAG: self.parse_extensions,
130
+ CF_TAG: self.parse_formatting,
131
+ LEGACY_TAG: self.parse_legacy,
132
+ ROW_BREAK_TAG: self.parse_row_breaks,
133
+ COL_BREAK_TAG: self.parse_col_breaks,
134
+ CUSTOM_VIEWS_TAG: self.parse_custom_views,
135
+ }
136
+
137
+ properties = {
138
+ PRINT_TAG: ('print_options', PrintOptions),
139
+ MARGINS_TAG: ('page_margins', PageMargins),
140
+ PAGE_TAG: ('page_setup', PrintPageSetup),
141
+ HEADER_TAG: ('HeaderFooter', HeaderFooter),
142
+ FILTER_TAG: ('auto_filter', AutoFilter),
143
+ VALIDATION_TAG: ('data_validations', DataValidationList),
144
+ PROPERTIES_TAG: ('sheet_properties', WorksheetProperties),
145
+ VIEWS_TAG: ('views', SheetViewList),
146
+ FORMAT_TAG: ('sheet_format', SheetFormatProperties),
147
+ SCENARIOS_TAG: ('scenarios', ScenarioList),
148
+ TABLE_TAG: ('tables', TablePartList),
149
+ HYPERLINK_TAG: ('hyperlinks', HyperlinkList),
150
+ MERGE_TAG: ('merged_cells', MergeCells),
151
+
152
+ }
153
+
154
+ it = iterparse(self.source) # add a finaliser to close the source when this becomes possible
155
+
156
+ for _, element in it:
157
+ tag_name = element.tag
158
+ if tag_name in dispatcher:
159
+ dispatcher[tag_name](element)
160
+ element.clear()
161
+ elif tag_name in properties:
162
+ prop = properties[tag_name]
163
+ obj = prop[1].from_tree(element)
164
+ setattr(self, prop[0], obj)
165
+ element.clear()
166
+ elif tag_name == ROW_TAG:
167
+ row = self.parse_row(element)
168
+ element.clear()
169
+ yield row
170
+
171
+
172
+ def parse_dimensions(self):
173
+ """
174
+ Get worksheet dimensions if they are provided.
175
+ """
176
+ it = iterparse(self.source)
177
+
178
+ for _event, element in it:
179
+ if element.tag == DIMENSION_TAG:
180
+ dim = SheetDimension.from_tree(element)
181
+ return dim.boundaries
182
+
183
+ elif element.tag == DATA_TAG:
184
+ # Dimensions missing
185
+ break
186
+ element.clear()
187
+
188
+
189
+ def parse_cell(self, element):
190
+ data_type = element.get('t', 'n')
191
+ coordinate = element.get('r')
192
+ style_id = element.get('s', 0)
193
+ if style_id:
194
+ style_id = int(style_id)
195
+
196
+ if data_type == "inlineStr":
197
+ value = None
198
+ else:
199
+ value = element.findtext(VALUE_TAG, None) or None
200
+
201
+ if coordinate:
202
+ row, column = coordinate_to_tuple(coordinate)
203
+ self.col_counter = column
204
+ else:
205
+ self.col_counter += 1
206
+ row, column = self.row_counter, self.col_counter
207
+
208
+ if not self.data_only and element.find(FORMULA_TAG) is not None:
209
+ data_type = 'f'
210
+ value = self.parse_formula(element)
211
+
212
+ elif value is not None:
213
+ if data_type == 'n':
214
+ value = _cast_number(value)
215
+ if style_id in self.date_formats:
216
+ data_type = 'd'
217
+ try:
218
+ value = from_excel(
219
+ value, self.epoch, timedelta=style_id in self.timedelta_formats
220
+ )
221
+ except (OverflowError, ValueError):
222
+ msg = f"""Cell {coordinate} is marked as a date but the serial value {value} is outside the limits for dates. The cell will be treated as an error."""
223
+ warn(msg)
224
+ data_type = "e"
225
+ value = "#VALUE!"
226
+ elif data_type == 's':
227
+ value = self.shared_strings[int(value)]
228
+ elif data_type == 'b':
229
+ value = bool(int(value))
230
+ elif data_type == "str":
231
+ data_type = "s"
232
+ elif data_type == 'd':
233
+ value = from_ISO8601(value)
234
+
235
+ elif data_type == 'inlineStr':
236
+ child = element.find(INLINE_STRING)
237
+ if child is not None:
238
+ data_type = 's'
239
+ if self.rich_text:
240
+ value = parse_richtext_string(child)
241
+ else:
242
+ value = Text.from_tree(child).content
243
+
244
+ return {'row':row, 'column':column, 'value':value, 'data_type':data_type, 'style_id':style_id}
245
+
246
+
247
+ def parse_formula(self, element):
248
+ """
249
+ possible formulae types: shared, array, datatable
250
+ """
251
+ formula = element.find(FORMULA_TAG)
252
+ formula_type = formula.get('t')
253
+ coordinate = element.get('r')
254
+ value = "="
255
+ if formula.text is not None:
256
+ value += formula.text
257
+
258
+ if formula_type == "array":
259
+ value = ArrayFormula(ref=formula.get('ref'), text=value)
260
+
261
+ elif formula_type == "shared":
262
+ idx = formula.get('si')
263
+ if idx in self.shared_formulae:
264
+ trans = self.shared_formulae[idx]
265
+ value = trans.translate_formula(coordinate)
266
+ elif value != "=":
267
+ self.shared_formulae[idx] = Translator(value, coordinate)
268
+
269
+ elif formula_type == "dataTable":
270
+ value = DataTableFormula(**formula.attrib)
271
+
272
+ return value
273
+
274
+
275
+ def parse_column_dimensions(self, col):
276
+ attrs = dict(col.attrib)
277
+ column = get_column_letter(int(attrs['min']))
278
+ attrs['index'] = column
279
+ self.column_dimensions[column] = attrs
280
+
281
+
282
+ def parse_row(self, row):
283
+ attrs = dict(row.attrib)
284
+
285
+ if "r" in attrs:
286
+ try:
287
+ self.row_counter = int(attrs['r'])
288
+ except ValueError:
289
+ val = float(attrs['r'])
290
+ if val.is_integer():
291
+ self.row_counter = int(val)
292
+ else:
293
+ raise ValueError(f"{attrs['r']} is not a valid row number")
294
+ else:
295
+ self.row_counter += 1
296
+ self.col_counter = 0
297
+
298
+ keys = {k for k in attrs if not k.startswith('{')}
299
+ if keys - {'r', 'spans'}:
300
+ # don't create dimension objects unless they have relevant information
301
+ self.row_dimensions[str(self.row_counter)] = attrs
302
+
303
+ cells = [self.parse_cell(el) for el in row]
304
+ return self.row_counter, cells
305
+
306
+
307
+ def parse_formatting(self, element):
308
+ try:
309
+ cf = ConditionalFormatting.from_tree(element)
310
+ self.formatting.append(cf)
311
+ except TypeError as e:
312
+ msg = f"Failed to load a conditional formatting rule. It will be discarded. Cause: {e}"
313
+ warn(msg)
314
+
315
+
316
+ def parse_sheet_protection(self, element):
317
+ protection = SheetProtection.from_tree(element)
318
+ password = element.get("password")
319
+ if password is not None:
320
+ protection.set_password(password, True)
321
+ self.protection = protection
322
+
323
+
324
+ def parse_extensions(self, element):
325
+ extLst = ExtensionList.from_tree(element)
326
+ for e in extLst.ext:
327
+ ext_type = EXT_TYPES.get(e.uri.upper(), "Unknown")
328
+ msg = "{0} extension is not supported and will be removed".format(ext_type)
329
+ warn(msg)
330
+
331
+
332
+ def parse_legacy(self, element):
333
+ obj = Related.from_tree(element)
334
+ self.legacy_drawing = obj.id
335
+
336
+
337
+ def parse_row_breaks(self, element):
338
+ brk = RowBreak.from_tree(element)
339
+ self.row_breaks = brk
340
+
341
+
342
+ def parse_col_breaks(self, element):
343
+ brk = ColBreak.from_tree(element)
344
+ self.col_breaks = brk
345
+
346
+
347
+ def parse_custom_views(self, element):
348
+ # clear page_breaks to avoid duplication which Excel doesn't like
349
+ # basically they're ignored in custom views
350
+ self.row_breaks = RowBreak()
351
+ self.col_breaks = ColBreak()
352
+
353
+
354
+ class WorksheetReader:
355
+ """
356
+ Create a parser and apply it to a workbook
357
+ """
358
+
359
+ def __init__(self, ws, xml_source, shared_strings, data_only, rich_text):
360
+ self.ws = ws
361
+ self.parser = WorkSheetParser(xml_source, shared_strings,
362
+ data_only, ws.parent.epoch, ws.parent._date_formats,
363
+ ws.parent._timedelta_formats, rich_text)
364
+ self.tables = []
365
+
366
+
367
+ def bind_cells(self):
368
+ for idx, row in self.parser.parse():
369
+ for cell in row:
370
+ style = self.ws.parent._cell_styles[cell['style_id']]
371
+ c = Cell(self.ws, row=cell['row'], column=cell['column'], style_array=style)
372
+ c._value = cell['value']
373
+ c.data_type = cell['data_type']
374
+ self.ws._cells[(cell['row'], cell['column'])] = c
375
+
376
+ if self.ws._cells:
377
+ self.ws._current_row = self.ws.max_row # use cells not row dimensions
378
+
379
+
380
+ def bind_formatting(self):
381
+ for cf in self.parser.formatting:
382
+ for rule in cf.rules:
383
+ if rule.dxfId is not None:
384
+ rule.dxf = self.ws.parent._differential_styles[rule.dxfId]
385
+ self.ws.conditional_formatting[cf] = rule
386
+
387
+
388
+ def bind_tables(self):
389
+ for t in self.parser.tables.tablePart:
390
+ rel = self.ws._rels.get(t.id)
391
+ self.tables.append(rel.Target)
392
+
393
+
394
+ def bind_merged_cells(self):
395
+ from openpyxl.worksheet.cell_range import MultiCellRange
396
+ from openpyxl.worksheet.merge import MergedCellRange
397
+ if not self.parser.merged_cells:
398
+ return
399
+
400
+ ranges = []
401
+ for cr in self.parser.merged_cells.mergeCell:
402
+ mcr = MergedCellRange(self.ws, cr.ref)
403
+ self.ws._clean_merge_range(mcr)
404
+ ranges.append(mcr)
405
+ self.ws.merged_cells = MultiCellRange(ranges)
406
+
407
+
408
+ def bind_hyperlinks(self):
409
+ for link in self.parser.hyperlinks.hyperlink:
410
+ if link.id:
411
+ rel = self.ws._rels.get(link.id)
412
+ link.target = rel.Target
413
+ if ":" in link.ref:
414
+ # range of cells
415
+ for row in self.ws[link.ref]:
416
+ for cell in row:
417
+ try:
418
+ cell.hyperlink = copy(link)
419
+ except AttributeError:
420
+ pass
421
+ else:
422
+ cell = self.ws[link.ref]
423
+ if isinstance(cell, MergedCell):
424
+ cell = self.normalize_merged_cell_link(cell.coordinate)
425
+ cell.hyperlink = link
426
+
427
+ def normalize_merged_cell_link(self, coord):
428
+ """
429
+ Returns the appropriate cell to which a hyperlink, which references a merged cell at the specified coordinates,
430
+ should be bound.
431
+ """
432
+ for rng in self.ws.merged_cells:
433
+ if coord in rng:
434
+ return self.ws.cell(*rng.top[0])
435
+
436
+ def bind_col_dimensions(self):
437
+ for col, cd in self.parser.column_dimensions.items():
438
+ if 'style' in cd:
439
+ key = int(cd['style'])
440
+ cd['style'] = self.ws.parent._cell_styles[key]
441
+ self.ws.column_dimensions[col] = ColumnDimension(self.ws, **cd)
442
+
443
+
444
+ def bind_row_dimensions(self):
445
+ for row, rd in self.parser.row_dimensions.items():
446
+ if 's' in rd:
447
+ key = int(rd['s'])
448
+ rd['s'] = self.ws.parent._cell_styles[key]
449
+ self.ws.row_dimensions[int(row)] = RowDimension(self.ws, **rd)
450
+
451
+
452
+ def bind_properties(self):
453
+ for k in ('print_options', 'page_margins', 'page_setup',
454
+ 'HeaderFooter', 'auto_filter', 'data_validations',
455
+ 'sheet_properties', 'views', 'sheet_format',
456
+ 'row_breaks', 'col_breaks', 'scenarios', 'legacy_drawing',
457
+ 'protection',
458
+ ):
459
+ v = getattr(self.parser, k, None)
460
+ if v is not None:
461
+ setattr(self.ws, k, v)
462
+
463
+
464
+ def bind_all(self):
465
+ self.bind_cells()
466
+ self.bind_merged_cells()
467
+ self.bind_hyperlinks()
468
+ self.bind_formatting()
469
+ self.bind_col_dimensions()
470
+ self.bind_row_dimensions()
471
+ self.bind_tables()
472
+ self.bind_properties()