@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,160 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+
4
+ """Write worksheets to xml representations in an optimized way"""
5
+
6
+ from inspect import isgenerator
7
+
8
+ from openpyxl.cell import Cell, WriteOnlyCell
9
+ from openpyxl.workbook.child import _WorkbookChild
10
+ from .worksheet import Worksheet
11
+ from openpyxl.utils.exceptions import WorkbookAlreadySaved
12
+
13
+ from ._writer import WorksheetWriter
14
+
15
+
16
+ class WriteOnlyWorksheet(_WorkbookChild):
17
+ """
18
+ Streaming worksheet. Optimised to reduce memory by writing rows just in
19
+ time.
20
+ Cells can be styled and have comments Styles for rows and columns
21
+ must be applied before writing cells
22
+ """
23
+
24
+ __saved = False
25
+ _writer = None
26
+ _rows = None
27
+ _rel_type = Worksheet._rel_type
28
+ _path = Worksheet._path
29
+ mime_type = Worksheet.mime_type
30
+
31
+ # copy methods from Standard worksheet
32
+ _add_row = Worksheet._add_row
33
+ _add_column = Worksheet._add_column
34
+ add_chart = Worksheet.add_chart
35
+ add_image = Worksheet.add_image
36
+ add_table = Worksheet.add_table
37
+ tables = Worksheet.tables
38
+ print_titles = Worksheet.print_titles
39
+ print_title_cols = Worksheet.print_title_cols
40
+ print_title_rows = Worksheet.print_title_rows
41
+ freeze_panes = Worksheet.freeze_panes
42
+ print_area = Worksheet.print_area
43
+ sheet_view = Worksheet.sheet_view
44
+ _setup = Worksheet._setup
45
+
46
+ def __init__(self, parent, title):
47
+ super().__init__(parent, title)
48
+ self._max_col = 0
49
+ self._max_row = 0
50
+ self._setup()
51
+
52
+ @property
53
+ def closed(self):
54
+ return self.__saved
55
+
56
+
57
+ def _write_rows(self):
58
+ """
59
+ Send rows to the writer's stream
60
+ """
61
+ try:
62
+ xf = self._writer.xf.send(True)
63
+ except StopIteration:
64
+ self._already_saved()
65
+
66
+ with xf.element("sheetData"):
67
+ row_idx = 1
68
+ try:
69
+ while True:
70
+ row = (yield)
71
+ row = self._values_to_row(row, row_idx)
72
+ self._writer.write_row(xf, row, row_idx)
73
+ row_idx += 1
74
+ except GeneratorExit:
75
+ pass
76
+
77
+ self._writer.xf.send(None)
78
+
79
+
80
+ def _get_writer(self):
81
+ if self._writer is None:
82
+ self._writer = WorksheetWriter(self)
83
+ self._writer.write_top()
84
+
85
+
86
+ def close(self):
87
+ if self.__saved:
88
+ self._already_saved()
89
+
90
+ self._get_writer()
91
+
92
+ if self._rows is None:
93
+ self._writer.write_rows()
94
+ else:
95
+ self._rows.close()
96
+
97
+ self._writer.write_tail()
98
+
99
+ self._writer.close()
100
+ self.__saved = True
101
+
102
+
103
+ def append(self, row):
104
+ """
105
+ :param row: iterable containing values to append
106
+ :type row: iterable
107
+ """
108
+
109
+ if (not isgenerator(row) and
110
+ not isinstance(row, (list, tuple, range))
111
+ ):
112
+ self._invalid_row(row)
113
+
114
+ self._get_writer()
115
+
116
+ if self._rows is None:
117
+ self._rows = self._write_rows()
118
+ next(self._rows)
119
+
120
+ self._rows.send(row)
121
+
122
+
123
+ def _values_to_row(self, values, row_idx):
124
+ """
125
+ Convert whatever has been appended into a form suitable for work_rows
126
+ """
127
+ cell = WriteOnlyCell(self)
128
+
129
+ for col_idx, value in enumerate(values, 1):
130
+ if value is None:
131
+ continue
132
+ try:
133
+ cell.value = value
134
+ except ValueError:
135
+ if isinstance(value, Cell):
136
+ cell = value
137
+ else:
138
+ raise ValueError
139
+
140
+ cell.column = col_idx
141
+ cell.row = row_idx
142
+
143
+ if cell.hyperlink is not None:
144
+ cell.hyperlink.ref = cell.coordinate
145
+
146
+ yield cell
147
+
148
+ # reset cell if style applied
149
+ if cell.has_style or cell.hyperlink:
150
+ cell = WriteOnlyCell(self)
151
+
152
+
153
+ def _already_saved(self):
154
+ raise WorkbookAlreadySaved('Workbook has already been saved and cannot be modified or saved anymore.')
155
+
156
+
157
+ def _invalid_row(self, iterable):
158
+ raise TypeError('Value must be a list, tuple, range or a generator Supplied value is {0}'.format(
159
+ type(iterable))
160
+ )
@@ -0,0 +1,390 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ import atexit
4
+ from collections import defaultdict
5
+ from io import BytesIO
6
+ import os
7
+ from tempfile import NamedTemporaryFile
8
+ from warnings import warn
9
+
10
+ from openpyxl.xml.functions import xmlfile
11
+ from openpyxl.xml.constants import SHEET_MAIN_NS
12
+
13
+ from openpyxl.comments.comment_sheet import CommentRecord
14
+ from openpyxl.packaging.relationship import Relationship, RelationshipList
15
+ from openpyxl.styles.differential import DifferentialStyle
16
+
17
+ from .dimensions import SheetDimension
18
+ from .hyperlink import HyperlinkList
19
+ from .merge import MergeCell, MergeCells
20
+ from .related import Related
21
+ from .table import TablePartList
22
+
23
+ from openpyxl.cell._writer import write_cell
24
+
25
+
26
+ ALL_TEMP_FILES = []
27
+
28
+ @atexit.register
29
+ def _openpyxl_shutdown():
30
+ for path in ALL_TEMP_FILES:
31
+ if os.path.exists(path):
32
+ os.remove(path)
33
+
34
+
35
+ def create_temporary_file(suffix=''):
36
+ fobj = NamedTemporaryFile(mode='w+', suffix=suffix,
37
+ prefix='openpyxl.', delete=False)
38
+ filename = fobj.name
39
+ fobj.close()
40
+ ALL_TEMP_FILES.append(filename)
41
+ return filename
42
+
43
+
44
+ class WorksheetWriter:
45
+
46
+
47
+ def __init__(self, ws, out=None):
48
+ self.ws = ws
49
+ self.ws._hyperlinks = []
50
+ self.ws._comments = []
51
+ if out is None:
52
+ out = create_temporary_file()
53
+ self.out = out
54
+ self._rels = RelationshipList()
55
+ self.xf = self.get_stream()
56
+ next(self.xf) # start generator
57
+
58
+
59
+ def write_properties(self):
60
+ props = self.ws.sheet_properties
61
+ self.xf.send(props.to_tree())
62
+
63
+
64
+ def write_dimensions(self):
65
+ """
66
+ Write worksheet size if known
67
+ """
68
+ ref = getattr(self.ws, 'calculate_dimension', None)
69
+ if ref:
70
+ dim = SheetDimension(ref())
71
+ self.xf.send(dim.to_tree())
72
+
73
+
74
+ def write_format(self):
75
+ self.ws.sheet_format.outlineLevelCol = self.ws.column_dimensions.max_outline
76
+ fmt = self.ws.sheet_format
77
+ self.xf.send(fmt.to_tree())
78
+
79
+
80
+ def write_views(self):
81
+ views = self.ws.views
82
+ self.xf.send(views.to_tree())
83
+
84
+
85
+ def write_cols(self):
86
+ cols = self.ws.column_dimensions
87
+ self.xf.send(cols.to_tree())
88
+
89
+
90
+ def write_top(self):
91
+ """
92
+ Write all elements up to rows:
93
+ properties
94
+ dimensions
95
+ views
96
+ format
97
+ cols
98
+ """
99
+ self.write_properties()
100
+ self.write_dimensions()
101
+ self.write_views()
102
+ self.write_format()
103
+ self.write_cols()
104
+
105
+
106
+ def rows(self):
107
+ """Return all rows, and any cells that they contain"""
108
+ # order cells by row
109
+ rows = defaultdict(list)
110
+ for (row, col), cell in sorted(self.ws._cells.items()):
111
+ rows[row].append(cell)
112
+
113
+ # add empty rows if styling has been applied
114
+ for row in self.ws.row_dimensions.keys() - rows.keys():
115
+ rows[row] = []
116
+
117
+ return sorted(rows.items())
118
+
119
+
120
+ def write_rows(self):
121
+ xf = self.xf.send(True)
122
+
123
+ with xf.element("sheetData"):
124
+ for row_idx, row in self.rows():
125
+ self.write_row(xf, row, row_idx)
126
+
127
+ self.xf.send(None) # return control to generator
128
+
129
+
130
+ def write_row(self, xf, row, row_idx):
131
+ attrs = {'r': f"{row_idx}"}
132
+ dims = self.ws.row_dimensions
133
+ attrs.update(dims.get(row_idx, {}))
134
+
135
+ with xf.element("row", attrs):
136
+
137
+ for cell in row:
138
+ if cell._comment is not None:
139
+ comment = CommentRecord.from_cell(cell)
140
+ self.ws._comments.append(comment)
141
+ if (
142
+ cell._value is None
143
+ and not cell.has_style
144
+ and not cell._comment
145
+ ):
146
+ continue
147
+ write_cell(xf, self.ws, cell, cell.has_style)
148
+
149
+
150
+ def write_protection(self):
151
+ prot = self.ws.protection
152
+ if prot:
153
+ self.xf.send(prot.to_tree())
154
+
155
+
156
+ def write_scenarios(self):
157
+ scenarios = self.ws.scenarios
158
+ if scenarios:
159
+ self.xf.send(scenarios.to_tree())
160
+
161
+
162
+ def write_filter(self):
163
+ flt = self.ws.auto_filter
164
+ if flt:
165
+ self.xf.send(flt.to_tree())
166
+
167
+
168
+ def write_sort(self):
169
+ """
170
+ As per discusion with the OOXML Working Group global sort state is not required.
171
+ openpyxl never reads it from existing files
172
+ """
173
+ pass
174
+
175
+
176
+ def write_merged_cells(self):
177
+ merged = self.ws.merged_cells
178
+ if merged:
179
+ cells = [MergeCell(str(ref)) for ref in self.ws.merged_cells]
180
+ self.xf.send(MergeCells(mergeCell=cells).to_tree())
181
+
182
+
183
+ def write_formatting(self):
184
+ df = DifferentialStyle()
185
+ wb = self.ws.parent
186
+ for cf in self.ws.conditional_formatting:
187
+ for rule in cf.rules:
188
+ if rule.dxf and rule.dxf != df:
189
+ rule.dxfId = wb._differential_styles.add(rule.dxf)
190
+ self.xf.send(cf.to_tree())
191
+
192
+
193
+ def write_validations(self):
194
+ dv = self.ws.data_validations
195
+ if dv:
196
+ self.xf.send(dv.to_tree())
197
+
198
+
199
+ def write_hyperlinks(self):
200
+
201
+ links = self.ws._hyperlinks
202
+
203
+ for link in links:
204
+ if link.target:
205
+ rel = Relationship(type="hyperlink", TargetMode="External", Target=link.target)
206
+ self._rels.append(rel)
207
+ link.id = rel.id
208
+
209
+ if links:
210
+ self.xf.send(HyperlinkList(links).to_tree())
211
+
212
+
213
+ def write_print(self):
214
+ print_options = self.ws.print_options
215
+ if print_options:
216
+ self.xf.send(print_options.to_tree())
217
+
218
+
219
+ def write_margins(self):
220
+ margins = self.ws.page_margins
221
+ if margins:
222
+ self.xf.send(margins.to_tree())
223
+
224
+
225
+ def write_page(self):
226
+ setup = self.ws.page_setup
227
+ if setup:
228
+ self.xf.send(setup.to_tree())
229
+
230
+
231
+ def write_header(self):
232
+ hf = self.ws.HeaderFooter
233
+ if hf:
234
+ self.xf.send(hf.to_tree())
235
+
236
+
237
+ def write_breaks(self):
238
+ brks = (self.ws.row_breaks, self.ws.col_breaks)
239
+ for brk in brks:
240
+ if brk:
241
+ self.xf.send(brk.to_tree())
242
+
243
+
244
+ def write_drawings(self):
245
+ if self.ws._charts or self.ws._images:
246
+ rel = Relationship(type="drawing", Target="")
247
+ self._rels.append(rel)
248
+ drawing = Related()
249
+ drawing.id = rel.id
250
+ self.xf.send(drawing.to_tree("drawing"))
251
+
252
+
253
+ def write_legacy(self):
254
+ """
255
+ Comments & VBA controls use VML and require an additional element
256
+ that is no longer in the specification.
257
+ """
258
+ if (self.ws.legacy_drawing is not None or self.ws._comments):
259
+ legacy = Related(id="anysvml")
260
+ self.xf.send(legacy.to_tree("legacyDrawing"))
261
+
262
+
263
+ def write_tables(self):
264
+ tables = TablePartList()
265
+
266
+ for table in self.ws.tables.values():
267
+ if not table.tableColumns:
268
+ table._initialise_columns()
269
+ if table.headerRowCount:
270
+ try:
271
+ row = self.ws[table.ref][0]
272
+ for cell, col in zip(row, table.tableColumns):
273
+ if cell.data_type != "s":
274
+ warn("File may not be readable: column headings must be strings.")
275
+ col.name = str(cell.value)
276
+ except TypeError:
277
+ warn("Column headings are missing, file may not be readable")
278
+ rel = Relationship(Type=table._rel_type, Target="")
279
+ self._rels.append(rel)
280
+ table._rel_id = rel.Id
281
+ tables.append(Related(id=rel.Id))
282
+
283
+ if tables:
284
+ self.xf.send(tables.to_tree())
285
+
286
+
287
+ def get_stream(self):
288
+ with xmlfile(self.out) as xf:
289
+ with xf.element("worksheet", xmlns=SHEET_MAIN_NS):
290
+ try:
291
+ while True:
292
+ el = (yield)
293
+ if el is True:
294
+ yield xf
295
+ elif el is None: # et_xmlfile chokes
296
+ continue
297
+ else:
298
+ xf.write(el)
299
+ except GeneratorExit:
300
+ pass
301
+
302
+
303
+ def write_tail(self):
304
+ """
305
+ Write all elements after the rows
306
+ calc properties
307
+ protection
308
+ protected ranges #
309
+ scenarios
310
+ filters
311
+ sorts # always ignored
312
+ data consolidation #
313
+ custom views #
314
+ merged cells
315
+ phonetic properties #
316
+ conditional formatting
317
+ data validation
318
+ hyperlinks
319
+ print options
320
+ page margins
321
+ page setup
322
+ header
323
+ row breaks
324
+ col breaks
325
+ custom properties #
326
+ cell watches #
327
+ ignored errors #
328
+ smart tags #
329
+ drawing
330
+ drawingHF #
331
+ background #
332
+ OLE objects #
333
+ controls #
334
+ web publishing #
335
+ tables
336
+ """
337
+ self.write_protection()
338
+ self.write_scenarios()
339
+ self.write_filter()
340
+ self.write_merged_cells()
341
+ self.write_formatting()
342
+ self.write_validations()
343
+ self.write_hyperlinks()
344
+ self.write_print()
345
+ self.write_margins()
346
+ self.write_page()
347
+ self.write_header()
348
+ self.write_breaks()
349
+ self.write_drawings()
350
+ self.write_legacy()
351
+ self.write_tables()
352
+
353
+
354
+ def write(self):
355
+ """
356
+ High level
357
+ """
358
+ self.write_top()
359
+ self.write_rows()
360
+ self.write_tail()
361
+ self.close()
362
+
363
+
364
+ def close(self):
365
+ """
366
+ Close the context manager
367
+ """
368
+ if self.xf:
369
+ self.xf.close()
370
+
371
+
372
+ def read(self):
373
+ """
374
+ Close the context manager and return serialised XML
375
+ """
376
+ self.close()
377
+ if isinstance(self.out, BytesIO):
378
+ return self.out.getvalue()
379
+ with open(self.out, "rb") as src:
380
+ out = src.read()
381
+
382
+ return out
383
+
384
+
385
+ def cleanup(self):
386
+ """
387
+ Remove tempfile
388
+ """
389
+ os.remove(self.out)
390
+ ALL_TEMP_FILES.remove(self.out)