@v587d/capital-generation 2.29.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 (299) hide show
  1. package/CHANGELOG.md +38 -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/tools.js +7 -7
  11. package/lib/python-runtime/errors.d.ts +1 -1
  12. package/lib/python-runtime/errors.js +2 -0
  13. package/lib/python-runtime/manager.d.ts +28 -1
  14. package/lib/python-runtime/manager.js +141 -5
  15. package/lib/python-runtime/probe.d.ts +24 -0
  16. package/lib/python-runtime/probe.js +66 -50
  17. package/lib/sources/csindex-http.d.ts +4 -0
  18. package/lib/sources/csindex-http.js +233 -0
  19. package/lib/sources/eastmoney-http.js +1504 -1
  20. package/lib/sources/fuyao-rest.js +168 -8
  21. package/lib/sources/official-http.d.ts +4 -0
  22. package/lib/sources/official-http.js +477 -0
  23. package/lib/sources/python-remote.d.ts +25 -0
  24. package/lib/sources/python-remote.js +461 -0
  25. package/lib/sources/sina-http.d.ts +2 -0
  26. package/lib/sources/sina-http.js +484 -0
  27. package/lib/sources/tencent-http.js +23 -8
  28. package/lib/sources/ths-http.d.ts +2 -0
  29. package/lib/sources/ths-http.js +514 -0
  30. package/lib/time/tools.js +19 -0
  31. package/lib/web-retriever/local-fetch.d.ts +1 -1
  32. package/lib/web-retriever/local-fetch.js +1 -1
  33. package/lib/web-retriever/sources.d.ts +7 -0
  34. package/lib/web-retriever/sources.js +46 -21
  35. package/lib/web-retriever/throttle.d.ts +8 -0
  36. package/lib/web-retriever/throttle.js +13 -0
  37. package/lib/web-retriever/tools.js +1 -1
  38. package/lib/web-retriever/wind-client.d.ts +1 -1
  39. package/lib/web-retriever/wind-client.js +1 -1
  40. package/package.json +1 -1
  41. package/preset/capital-generation/agent.patch.yml +7 -5
  42. package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
  43. package/python/scripts/baostock_stock_basic.py +129 -0
  44. package/python/scripts/baostock_valuation_history.py +141 -0
  45. package/python/scripts/pbc_social_financing.py +291 -0
  46. package/python/vendor/baostock/LICENSE +19 -0
  47. package/python/vendor/baostock/__init__.py +42 -0
  48. package/python/vendor/baostock/common/__init__.py +0 -0
  49. package/python/vendor/baostock/common/contants.py +189 -0
  50. package/python/vendor/baostock/common/context.py +4 -0
  51. package/python/vendor/baostock/corpreport/__init__.py +0 -0
  52. package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
  53. package/python/vendor/baostock/data/__init__.py +0 -0
  54. package/python/vendor/baostock/data/messageheader.py +17 -0
  55. package/python/vendor/baostock/data/msg.py +21 -0
  56. package/python/vendor/baostock/data/resultset.py +200 -0
  57. package/python/vendor/baostock/demo/__init__.py +0 -0
  58. package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
  59. package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
  60. package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
  61. package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
  62. package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
  63. package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
  64. package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
  65. package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
  66. package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
  67. package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
  68. package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
  69. package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
  70. package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
  71. package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
  72. package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
  73. package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
  74. package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
  75. package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
  76. package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
  77. package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
  78. package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
  79. package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
  80. package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
  81. package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
  82. package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
  83. package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
  84. package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
  85. package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
  86. package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
  87. package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
  88. package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
  89. package/python/vendor/baostock/evaluation/__init__.py +0 -0
  90. package/python/vendor/baostock/evaluation/season_index.py +758 -0
  91. package/python/vendor/baostock/login/__init__.py +0 -0
  92. package/python/vendor/baostock/login/loginout.py +230 -0
  93. package/python/vendor/baostock/macroscopic/__init__.py +0 -0
  94. package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
  95. package/python/vendor/baostock/metadata/__init__.py +0 -0
  96. package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
  97. package/python/vendor/baostock/security/__init__.py +0 -0
  98. package/python/vendor/baostock/security/history.py +265 -0
  99. package/python/vendor/baostock/security/sectorinfo.py +1024 -0
  100. package/python/vendor/baostock/util/__init__.py +0 -0
  101. package/python/vendor/baostock/util/socketutil.py +97 -0
  102. package/python/vendor/baostock/util/stringutil.py +83 -0
  103. package/python/vendor/et_xmlfile/LICENSE +23 -0
  104. package/python/vendor/et_xmlfile/LICENSE.python +298 -0
  105. package/python/vendor/et_xmlfile/__init__.py +8 -0
  106. package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
  107. package/python/vendor/et_xmlfile/xmlfile.py +158 -0
  108. package/python/vendor/openpyxl/LICENSE +23 -0
  109. package/python/vendor/openpyxl/__init__.py +19 -0
  110. package/python/vendor/openpyxl/_constants.py +13 -0
  111. package/python/vendor/openpyxl/cell/__init__.py +4 -0
  112. package/python/vendor/openpyxl/cell/_writer.py +136 -0
  113. package/python/vendor/openpyxl/cell/cell.py +332 -0
  114. package/python/vendor/openpyxl/cell/read_only.py +136 -0
  115. package/python/vendor/openpyxl/cell/rich_text.py +202 -0
  116. package/python/vendor/openpyxl/cell/text.py +184 -0
  117. package/python/vendor/openpyxl/chart/_3d.py +105 -0
  118. package/python/vendor/openpyxl/chart/__init__.py +19 -0
  119. package/python/vendor/openpyxl/chart/_chart.py +199 -0
  120. package/python/vendor/openpyxl/chart/area_chart.py +106 -0
  121. package/python/vendor/openpyxl/chart/axis.py +401 -0
  122. package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
  123. package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
  124. package/python/vendor/openpyxl/chart/chartspace.py +195 -0
  125. package/python/vendor/openpyxl/chart/data_source.py +246 -0
  126. package/python/vendor/openpyxl/chart/descriptors.py +43 -0
  127. package/python/vendor/openpyxl/chart/error_bar.py +62 -0
  128. package/python/vendor/openpyxl/chart/label.py +127 -0
  129. package/python/vendor/openpyxl/chart/layout.py +74 -0
  130. package/python/vendor/openpyxl/chart/legend.py +75 -0
  131. package/python/vendor/openpyxl/chart/line_chart.py +129 -0
  132. package/python/vendor/openpyxl/chart/marker.py +90 -0
  133. package/python/vendor/openpyxl/chart/picture.py +35 -0
  134. package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
  135. package/python/vendor/openpyxl/chart/pivot.py +65 -0
  136. package/python/vendor/openpyxl/chart/plotarea.py +162 -0
  137. package/python/vendor/openpyxl/chart/print_settings.py +57 -0
  138. package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
  139. package/python/vendor/openpyxl/chart/reader.py +32 -0
  140. package/python/vendor/openpyxl/chart/reference.py +124 -0
  141. package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
  142. package/python/vendor/openpyxl/chart/series.py +197 -0
  143. package/python/vendor/openpyxl/chart/series_factory.py +41 -0
  144. package/python/vendor/openpyxl/chart/shapes.py +89 -0
  145. package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
  146. package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
  147. package/python/vendor/openpyxl/chart/text.py +78 -0
  148. package/python/vendor/openpyxl/chart/title.py +76 -0
  149. package/python/vendor/openpyxl/chart/trendline.py +98 -0
  150. package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
  151. package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
  152. package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
  153. package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
  154. package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
  155. package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
  156. package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
  157. package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
  158. package/python/vendor/openpyxl/chartsheet/views.py +51 -0
  159. package/python/vendor/openpyxl/comments/__init__.py +4 -0
  160. package/python/vendor/openpyxl/comments/author.py +21 -0
  161. package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
  162. package/python/vendor/openpyxl/comments/comments.py +62 -0
  163. package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
  164. package/python/vendor/openpyxl/compat/__init__.py +54 -0
  165. package/python/vendor/openpyxl/compat/abc.py +8 -0
  166. package/python/vendor/openpyxl/compat/numbers.py +43 -0
  167. package/python/vendor/openpyxl/compat/product.py +17 -0
  168. package/python/vendor/openpyxl/compat/singleton.py +40 -0
  169. package/python/vendor/openpyxl/compat/strings.py +25 -0
  170. package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
  171. package/python/vendor/openpyxl/descriptors/base.py +272 -0
  172. package/python/vendor/openpyxl/descriptors/container.py +41 -0
  173. package/python/vendor/openpyxl/descriptors/excel.py +112 -0
  174. package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
  175. package/python/vendor/openpyxl/descriptors/nested.py +129 -0
  176. package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
  177. package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
  178. package/python/vendor/openpyxl/descriptors/slots.py +18 -0
  179. package/python/vendor/openpyxl/drawing/__init__.py +4 -0
  180. package/python/vendor/openpyxl/drawing/colors.py +435 -0
  181. package/python/vendor/openpyxl/drawing/connector.py +144 -0
  182. package/python/vendor/openpyxl/drawing/drawing.py +92 -0
  183. package/python/vendor/openpyxl/drawing/effect.py +407 -0
  184. package/python/vendor/openpyxl/drawing/fill.py +425 -0
  185. package/python/vendor/openpyxl/drawing/geometry.py +584 -0
  186. package/python/vendor/openpyxl/drawing/graphic.py +177 -0
  187. package/python/vendor/openpyxl/drawing/image.py +65 -0
  188. package/python/vendor/openpyxl/drawing/line.py +144 -0
  189. package/python/vendor/openpyxl/drawing/picture.py +144 -0
  190. package/python/vendor/openpyxl/drawing/properties.py +174 -0
  191. package/python/vendor/openpyxl/drawing/relation.py +17 -0
  192. package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
  193. package/python/vendor/openpyxl/drawing/text.py +717 -0
  194. package/python/vendor/openpyxl/drawing/xdr.py +33 -0
  195. package/python/vendor/openpyxl/formatting/__init__.py +3 -0
  196. package/python/vendor/openpyxl/formatting/formatting.py +114 -0
  197. package/python/vendor/openpyxl/formatting/rule.py +291 -0
  198. package/python/vendor/openpyxl/formula/__init__.py +3 -0
  199. package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
  200. package/python/vendor/openpyxl/formula/translate.py +166 -0
  201. package/python/vendor/openpyxl/packaging/__init__.py +3 -0
  202. package/python/vendor/openpyxl/packaging/core.py +115 -0
  203. package/python/vendor/openpyxl/packaging/custom.py +289 -0
  204. package/python/vendor/openpyxl/packaging/extended.py +137 -0
  205. package/python/vendor/openpyxl/packaging/interface.py +56 -0
  206. package/python/vendor/openpyxl/packaging/manifest.py +194 -0
  207. package/python/vendor/openpyxl/packaging/relationship.py +158 -0
  208. package/python/vendor/openpyxl/packaging/workbook.py +185 -0
  209. package/python/vendor/openpyxl/pivot/__init__.py +1 -0
  210. package/python/vendor/openpyxl/pivot/cache.py +965 -0
  211. package/python/vendor/openpyxl/pivot/fields.py +326 -0
  212. package/python/vendor/openpyxl/pivot/record.py +111 -0
  213. package/python/vendor/openpyxl/pivot/table.py +1261 -0
  214. package/python/vendor/openpyxl/reader/__init__.py +1 -0
  215. package/python/vendor/openpyxl/reader/drawings.py +71 -0
  216. package/python/vendor/openpyxl/reader/excel.py +349 -0
  217. package/python/vendor/openpyxl/reader/strings.py +44 -0
  218. package/python/vendor/openpyxl/reader/workbook.py +133 -0
  219. package/python/vendor/openpyxl/styles/__init__.py +11 -0
  220. package/python/vendor/openpyxl/styles/alignment.py +62 -0
  221. package/python/vendor/openpyxl/styles/borders.py +103 -0
  222. package/python/vendor/openpyxl/styles/builtins.py +1397 -0
  223. package/python/vendor/openpyxl/styles/cell_style.py +206 -0
  224. package/python/vendor/openpyxl/styles/colors.py +172 -0
  225. package/python/vendor/openpyxl/styles/differential.py +95 -0
  226. package/python/vendor/openpyxl/styles/fills.py +224 -0
  227. package/python/vendor/openpyxl/styles/fonts.py +113 -0
  228. package/python/vendor/openpyxl/styles/named_styles.py +282 -0
  229. package/python/vendor/openpyxl/styles/numbers.py +200 -0
  230. package/python/vendor/openpyxl/styles/protection.py +17 -0
  231. package/python/vendor/openpyxl/styles/proxy.py +62 -0
  232. package/python/vendor/openpyxl/styles/styleable.py +151 -0
  233. package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
  234. package/python/vendor/openpyxl/styles/table.py +94 -0
  235. package/python/vendor/openpyxl/utils/__init__.py +17 -0
  236. package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
  237. package/python/vendor/openpyxl/utils/cell.py +240 -0
  238. package/python/vendor/openpyxl/utils/dataframe.py +87 -0
  239. package/python/vendor/openpyxl/utils/datetime.py +140 -0
  240. package/python/vendor/openpyxl/utils/escape.py +43 -0
  241. package/python/vendor/openpyxl/utils/exceptions.py +34 -0
  242. package/python/vendor/openpyxl/utils/formulas.py +24 -0
  243. package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
  244. package/python/vendor/openpyxl/utils/inference.py +60 -0
  245. package/python/vendor/openpyxl/utils/protection.py +22 -0
  246. package/python/vendor/openpyxl/utils/units.py +108 -0
  247. package/python/vendor/openpyxl/workbook/__init__.py +4 -0
  248. package/python/vendor/openpyxl/workbook/_writer.py +197 -0
  249. package/python/vendor/openpyxl/workbook/child.py +166 -0
  250. package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
  251. package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
  252. package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
  253. package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
  254. package/python/vendor/openpyxl/workbook/function_group.py +36 -0
  255. package/python/vendor/openpyxl/workbook/properties.py +151 -0
  256. package/python/vendor/openpyxl/workbook/protection.py +163 -0
  257. package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
  258. package/python/vendor/openpyxl/workbook/views.py +155 -0
  259. package/python/vendor/openpyxl/workbook/web.py +98 -0
  260. package/python/vendor/openpyxl/workbook/workbook.py +438 -0
  261. package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
  262. package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
  263. package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
  264. package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
  265. package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
  266. package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
  267. package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
  268. package/python/vendor/openpyxl/worksheet/controls.py +107 -0
  269. package/python/vendor/openpyxl/worksheet/copier.py +70 -0
  270. package/python/vendor/openpyxl/worksheet/custom.py +35 -0
  271. package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
  272. package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
  273. package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
  274. package/python/vendor/openpyxl/worksheet/errors.py +93 -0
  275. package/python/vendor/openpyxl/worksheet/filters.py +486 -0
  276. package/python/vendor/openpyxl/worksheet/formula.py +51 -0
  277. package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
  278. package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
  279. package/python/vendor/openpyxl/worksheet/merge.py +141 -0
  280. package/python/vendor/openpyxl/worksheet/ole.py +133 -0
  281. package/python/vendor/openpyxl/worksheet/page.py +174 -0
  282. package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
  283. package/python/vendor/openpyxl/worksheet/picture.py +8 -0
  284. package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
  285. package/python/vendor/openpyxl/worksheet/properties.py +97 -0
  286. package/python/vendor/openpyxl/worksheet/protection.py +120 -0
  287. package/python/vendor/openpyxl/worksheet/related.py +17 -0
  288. package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
  289. package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
  290. package/python/vendor/openpyxl/worksheet/table.py +385 -0
  291. package/python/vendor/openpyxl/worksheet/views.py +155 -0
  292. package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
  293. package/python/vendor/openpyxl/writer/__init__.py +1 -0
  294. package/python/vendor/openpyxl/writer/excel.py +295 -0
  295. package/python/vendor/openpyxl/writer/theme.py +291 -0
  296. package/python/vendor/openpyxl/xml/__init__.py +42 -0
  297. package/python/vendor/openpyxl/xml/constants.py +129 -0
  298. package/python/vendor/openpyxl/xml/functions.py +87 -0
  299. package/watchlist/package.json +1 -1
@@ -0,0 +1,907 @@
1
+ # Copyright (c) 2010-2024 openpyxl
2
+
3
+ """Worksheet is the 2nd-level container in Excel."""
4
+
5
+
6
+ # Python stdlib imports
7
+ from itertools import chain
8
+ from operator import itemgetter
9
+ from inspect import isgenerator
10
+ from warnings import warn
11
+
12
+ # compatibility imports
13
+ from openpyxl.compat import (
14
+ deprecated,
15
+ )
16
+
17
+ # package imports
18
+ from openpyxl.utils import (
19
+ column_index_from_string,
20
+ get_column_letter,
21
+ range_boundaries,
22
+ coordinate_to_tuple,
23
+ )
24
+ from openpyxl.cell import Cell, MergedCell
25
+ from openpyxl.formatting.formatting import ConditionalFormattingList
26
+ from openpyxl.packaging.relationship import RelationshipList
27
+ from openpyxl.workbook.child import _WorkbookChild
28
+ from openpyxl.workbook.defined_name import (
29
+ DefinedNameDict,
30
+ )
31
+
32
+ from openpyxl.formula.translate import Translator
33
+
34
+ from .datavalidation import DataValidationList
35
+ from .page import (
36
+ PrintPageSetup,
37
+ PageMargins,
38
+ PrintOptions,
39
+ )
40
+ from .dimensions import (
41
+ ColumnDimension,
42
+ RowDimension,
43
+ DimensionHolder,
44
+ SheetFormatProperties,
45
+ )
46
+ from .protection import SheetProtection
47
+ from .filters import AutoFilter
48
+ from .views import (
49
+ Pane,
50
+ Selection,
51
+ SheetViewList,
52
+ )
53
+ from .cell_range import MultiCellRange, CellRange
54
+ from .merge import MergedCellRange
55
+ from .properties import WorksheetProperties
56
+ from .pagebreak import RowBreak, ColBreak
57
+ from .scenario import ScenarioList
58
+ from .table import TableList
59
+ from .formula import ArrayFormula
60
+ from .print_settings import (
61
+ PrintTitles,
62
+ ColRange,
63
+ RowRange,
64
+ PrintArea,
65
+ )
66
+
67
+
68
+ class Worksheet(_WorkbookChild):
69
+ """Represents a worksheet.
70
+
71
+ Do not create worksheets yourself,
72
+ use :func:`openpyxl.workbook.Workbook.create_sheet` instead
73
+
74
+ """
75
+
76
+ _rel_type = "worksheet"
77
+ _path = "/xl/worksheets/sheet{0}.xml"
78
+ mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
79
+
80
+ BREAK_NONE = 0
81
+ BREAK_ROW = 1
82
+ BREAK_COLUMN = 2
83
+
84
+ SHEETSTATE_VISIBLE = 'visible'
85
+ SHEETSTATE_HIDDEN = 'hidden'
86
+ SHEETSTATE_VERYHIDDEN = 'veryHidden'
87
+
88
+ # Paper size
89
+ PAPERSIZE_LETTER = '1'
90
+ PAPERSIZE_LETTER_SMALL = '2'
91
+ PAPERSIZE_TABLOID = '3'
92
+ PAPERSIZE_LEDGER = '4'
93
+ PAPERSIZE_LEGAL = '5'
94
+ PAPERSIZE_STATEMENT = '6'
95
+ PAPERSIZE_EXECUTIVE = '7'
96
+ PAPERSIZE_A3 = '8'
97
+ PAPERSIZE_A4 = '9'
98
+ PAPERSIZE_A4_SMALL = '10'
99
+ PAPERSIZE_A5 = '11'
100
+
101
+ # Page orientation
102
+ ORIENTATION_PORTRAIT = 'portrait'
103
+ ORIENTATION_LANDSCAPE = 'landscape'
104
+
105
+ def __init__(self, parent, title=None):
106
+ _WorkbookChild.__init__(self, parent, title)
107
+ self._setup()
108
+
109
+ def _setup(self):
110
+ self.row_dimensions = DimensionHolder(worksheet=self,
111
+ default_factory=self._add_row)
112
+ self.column_dimensions = DimensionHolder(worksheet=self,
113
+ default_factory=self._add_column)
114
+ self.row_breaks = RowBreak()
115
+ self.col_breaks = ColBreak()
116
+ self._cells = {}
117
+ self._charts = []
118
+ self._images = []
119
+ self._rels = RelationshipList()
120
+ self._drawing = None
121
+ self._comments = []
122
+ self.merged_cells = MultiCellRange()
123
+ self._tables = TableList()
124
+ self._pivots = []
125
+ self.data_validations = DataValidationList()
126
+ self._hyperlinks = []
127
+ self.sheet_state = 'visible'
128
+ self.page_setup = PrintPageSetup(worksheet=self)
129
+ self.print_options = PrintOptions()
130
+ self._print_rows = None
131
+ self._print_cols = None
132
+ self._print_area = PrintArea()
133
+ self.page_margins = PageMargins()
134
+ self.views = SheetViewList()
135
+ self.protection = SheetProtection()
136
+ self.defined_names = DefinedNameDict()
137
+
138
+ self._current_row = 0
139
+ self.auto_filter = AutoFilter()
140
+ self.conditional_formatting = ConditionalFormattingList()
141
+ self.legacy_drawing = None
142
+ self.sheet_properties = WorksheetProperties()
143
+ self.sheet_format = SheetFormatProperties()
144
+ self.scenarios = ScenarioList()
145
+
146
+
147
+ @property
148
+ def sheet_view(self):
149
+ return self.views.active
150
+
151
+
152
+ @property
153
+ def selected_cell(self):
154
+ return self.sheet_view.selection[0].sqref
155
+
156
+
157
+ @property
158
+ def active_cell(self):
159
+ return self.sheet_view.selection[0].activeCell
160
+
161
+
162
+ @property
163
+ def array_formulae(self):
164
+ """Returns a dictionary of cells with array formulae and the cells in array"""
165
+ result = {}
166
+ for c in self._cells.values():
167
+ if c.data_type == "f":
168
+ if isinstance(c.value, ArrayFormula):
169
+ result[c.coordinate] = c.value.ref
170
+ return result
171
+
172
+
173
+ @property
174
+ def show_gridlines(self):
175
+ return self.sheet_view.showGridLines
176
+
177
+
178
+ @property
179
+ def freeze_panes(self):
180
+ if self.sheet_view.pane is not None:
181
+ return self.sheet_view.pane.topLeftCell
182
+
183
+
184
+ @freeze_panes.setter
185
+ def freeze_panes(self, topLeftCell=None):
186
+ if isinstance(topLeftCell, Cell):
187
+ topLeftCell = topLeftCell.coordinate
188
+ if topLeftCell == 'A1':
189
+ topLeftCell = None
190
+
191
+ if not topLeftCell:
192
+ self.sheet_view.pane = None
193
+ return
194
+
195
+ row, column = coordinate_to_tuple(topLeftCell)
196
+
197
+ view = self.sheet_view
198
+ view.pane = Pane(topLeftCell=topLeftCell,
199
+ activePane="topRight",
200
+ state="frozen")
201
+ view.selection[0].pane = "topRight"
202
+
203
+ if column > 1:
204
+ view.pane.xSplit = column - 1
205
+ if row > 1:
206
+ view.pane.ySplit = row - 1
207
+ view.pane.activePane = 'bottomLeft'
208
+ view.selection[0].pane = "bottomLeft"
209
+ if column > 1:
210
+ view.selection[0].pane = "bottomRight"
211
+ view.pane.activePane = 'bottomRight'
212
+
213
+ if row > 1 and column > 1:
214
+ sel = list(view.selection)
215
+ sel.insert(0, Selection(pane="topRight", activeCell=None, sqref=None))
216
+ sel.insert(1, Selection(pane="bottomLeft", activeCell=None, sqref=None))
217
+ view.selection = sel
218
+
219
+
220
+ def cell(self, row, column, value=None):
221
+ """
222
+ Returns a cell object based on the given coordinates.
223
+
224
+ Usage: cell(row=15, column=1, value=5)
225
+
226
+ Calling `cell` creates cells in memory when they
227
+ are first accessed.
228
+
229
+ :param row: row index of the cell (e.g. 4)
230
+ :type row: int
231
+
232
+ :param column: column index of the cell (e.g. 3)
233
+ :type column: int
234
+
235
+ :param value: value of the cell (e.g. 5)
236
+ :type value: numeric or time or string or bool or none
237
+
238
+ :rtype: openpyxl.cell.cell.Cell
239
+ """
240
+
241
+ if row < 1 or column < 1:
242
+ raise ValueError("Row or column values must be at least 1")
243
+
244
+ cell = self._get_cell(row, column)
245
+ if value is not None:
246
+ cell.value = value
247
+
248
+ return cell
249
+
250
+
251
+ def _get_cell(self, row, column):
252
+ """
253
+ Internal method for getting a cell from a worksheet.
254
+ Will create a new cell if one doesn't already exist.
255
+ """
256
+ if not 0 < row < 1048577:
257
+ raise ValueError(f"Row numbers must be between 1 and 1048576. Row number supplied was {row}")
258
+ coordinate = (row, column)
259
+ if not coordinate in self._cells:
260
+ cell = Cell(self, row=row, column=column)
261
+ self._add_cell(cell)
262
+ return self._cells[coordinate]
263
+
264
+
265
+ def _add_cell(self, cell):
266
+ """
267
+ Internal method for adding cell objects.
268
+ """
269
+ column = cell.col_idx
270
+ row = cell.row
271
+ self._current_row = max(row, self._current_row)
272
+ self._cells[(row, column)] = cell
273
+
274
+
275
+ def __getitem__(self, key):
276
+ """Convenience access by Excel style coordinates
277
+
278
+ The key can be a single cell coordinate 'A1', a range of cells 'A1:D25',
279
+ individual rows or columns 'A', 4 or ranges of rows or columns 'A:D',
280
+ 4:10.
281
+
282
+ Single cells will always be created if they do not exist.
283
+
284
+ Returns either a single cell or a tuple of rows or columns.
285
+ """
286
+ if isinstance(key, slice):
287
+ if not all([key.start, key.stop]):
288
+ raise IndexError("{0} is not a valid coordinate or range".format(key))
289
+ key = "{0}:{1}".format(key.start, key.stop)
290
+
291
+ if isinstance(key, int):
292
+ key = str(key
293
+ )
294
+ min_col, min_row, max_col, max_row = range_boundaries(key)
295
+
296
+ if not any([min_col, min_row, max_col, max_row]):
297
+ raise IndexError("{0} is not a valid coordinate or range".format(key))
298
+
299
+ if min_row is None:
300
+ cols = tuple(self.iter_cols(min_col, max_col))
301
+ if min_col == max_col:
302
+ cols = cols[0]
303
+ return cols
304
+ if min_col is None:
305
+ rows = tuple(self.iter_rows(min_col=min_col, min_row=min_row,
306
+ max_col=self.max_column, max_row=max_row))
307
+ if min_row == max_row:
308
+ rows = rows[0]
309
+ return rows
310
+ if ":" not in key:
311
+ return self._get_cell(min_row, min_col)
312
+ return tuple(self.iter_rows(min_row=min_row, min_col=min_col,
313
+ max_row=max_row, max_col=max_col))
314
+
315
+
316
+ def __setitem__(self, key, value):
317
+ self[key].value = value
318
+
319
+
320
+ def __iter__(self):
321
+ return self.iter_rows()
322
+
323
+
324
+ def __delitem__(self, key):
325
+ row, column = coordinate_to_tuple(key)
326
+ if (row, column) in self._cells:
327
+ del self._cells[(row, column)]
328
+
329
+
330
+ @property
331
+ def min_row(self):
332
+ """The minimum row index containing data (1-based)
333
+
334
+ :type: int
335
+ """
336
+ min_row = 1
337
+ if self._cells:
338
+ min_row = min(self._cells)[0]
339
+ return min_row
340
+
341
+
342
+ @property
343
+ def max_row(self):
344
+ """The maximum row index containing data (1-based)
345
+
346
+ :type: int
347
+ """
348
+ max_row = 1
349
+ if self._cells:
350
+ max_row = max(self._cells)[0]
351
+ return max_row
352
+
353
+
354
+ @property
355
+ def min_column(self):
356
+ """The minimum column index containing data (1-based)
357
+
358
+ :type: int
359
+ """
360
+ min_col = 1
361
+ if self._cells:
362
+ min_col = min(c[1] for c in self._cells)
363
+ return min_col
364
+
365
+
366
+ @property
367
+ def max_column(self):
368
+ """The maximum column index containing data (1-based)
369
+
370
+ :type: int
371
+ """
372
+ max_col = 1
373
+ if self._cells:
374
+ max_col = max(c[1] for c in self._cells)
375
+ return max_col
376
+
377
+
378
+ def calculate_dimension(self):
379
+ """Return the minimum bounding range for all cells containing data (ex. 'A1:M24')
380
+
381
+ :rtype: string
382
+ """
383
+ if self._cells:
384
+ rows = set()
385
+ cols = set()
386
+ for row, col in self._cells:
387
+ rows.add(row)
388
+ cols.add(col)
389
+ max_row = max(rows)
390
+ max_col = max(cols)
391
+ min_col = min(cols)
392
+ min_row = min(rows)
393
+ else:
394
+ return "A1:A1"
395
+
396
+ return f"{get_column_letter(min_col)}{min_row}:{get_column_letter(max_col)}{max_row}"
397
+
398
+
399
+ @property
400
+ def dimensions(self):
401
+ """Returns the result of :func:`calculate_dimension`"""
402
+ return self.calculate_dimension()
403
+
404
+
405
+ def iter_rows(self, min_row=None, max_row=None, min_col=None, max_col=None, values_only=False):
406
+ """
407
+ Produces cells from the worksheet, by row. Specify the iteration range
408
+ using indices of rows and columns.
409
+
410
+ If no indices are specified the range starts at A1.
411
+
412
+ If no cells are in the worksheet an empty tuple will be returned.
413
+
414
+ :param min_col: smallest column index (1-based index)
415
+ :type min_col: int
416
+
417
+ :param min_row: smallest row index (1-based index)
418
+ :type min_row: int
419
+
420
+ :param max_col: largest column index (1-based index)
421
+ :type max_col: int
422
+
423
+ :param max_row: largest row index (1-based index)
424
+ :type max_row: int
425
+
426
+ :param values_only: whether only cell values should be returned
427
+ :type values_only: bool
428
+
429
+ :rtype: generator
430
+ """
431
+
432
+ if self._current_row == 0 and not any([min_col, min_row, max_col, max_row ]):
433
+ return iter(())
434
+
435
+
436
+ min_col = min_col or 1
437
+ min_row = min_row or 1
438
+ max_col = max_col or self.max_column
439
+ max_row = max_row or self.max_row
440
+
441
+ return self._cells_by_row(min_col, min_row, max_col, max_row, values_only)
442
+
443
+
444
+ def _cells_by_row(self, min_col, min_row, max_col, max_row, values_only=False):
445
+ for row in range(min_row, max_row + 1):
446
+ cells = (self.cell(row=row, column=column) for column in range(min_col, max_col + 1))
447
+ if values_only:
448
+ yield tuple(cell.value for cell in cells)
449
+ else:
450
+ yield tuple(cells)
451
+
452
+
453
+ @property
454
+ def rows(self):
455
+ """Produces all cells in the worksheet, by row (see :func:`iter_rows`)
456
+
457
+ :type: generator
458
+ """
459
+ return self.iter_rows()
460
+
461
+
462
+ @property
463
+ def values(self):
464
+ """Produces all cell values in the worksheet, by row
465
+
466
+ :type: generator
467
+ """
468
+ for row in self.iter_rows(values_only=True):
469
+ yield row
470
+
471
+
472
+ def iter_cols(self, min_col=None, max_col=None, min_row=None, max_row=None, values_only=False):
473
+ """
474
+ Produces cells from the worksheet, by column. Specify the iteration range
475
+ using indices of rows and columns.
476
+
477
+ If no indices are specified the range starts at A1.
478
+
479
+ If no cells are in the worksheet an empty tuple will be returned.
480
+
481
+ :param min_col: smallest column index (1-based index)
482
+ :type min_col: int
483
+
484
+ :param min_row: smallest row index (1-based index)
485
+ :type min_row: int
486
+
487
+ :param max_col: largest column index (1-based index)
488
+ :type max_col: int
489
+
490
+ :param max_row: largest row index (1-based index)
491
+ :type max_row: int
492
+
493
+ :param values_only: whether only cell values should be returned
494
+ :type values_only: bool
495
+
496
+ :rtype: generator
497
+ """
498
+
499
+ if self._current_row == 0 and not any([min_col, min_row, max_col, max_row]):
500
+ return iter(())
501
+
502
+ min_col = min_col or 1
503
+ min_row = min_row or 1
504
+ max_col = max_col or self.max_column
505
+ max_row = max_row or self.max_row
506
+
507
+ return self._cells_by_col(min_col, min_row, max_col, max_row, values_only)
508
+
509
+
510
+ def _cells_by_col(self, min_col, min_row, max_col, max_row, values_only=False):
511
+ """
512
+ Get cells by column
513
+ """
514
+ for column in range(min_col, max_col+1):
515
+ cells = (self.cell(row=row, column=column)
516
+ for row in range(min_row, max_row+1))
517
+ if values_only:
518
+ yield tuple(cell.value for cell in cells)
519
+ else:
520
+ yield tuple(cells)
521
+
522
+
523
+ @property
524
+ def columns(self):
525
+ """Produces all cells in the worksheet, by column (see :func:`iter_cols`)"""
526
+ return self.iter_cols()
527
+
528
+
529
+ @property
530
+ def column_groups(self):
531
+ """
532
+ Return a list of column ranges where more than one column
533
+ """
534
+ return [cd.range for cd in self.column_dimensions.values() if cd.min and cd.max > cd.min]
535
+
536
+
537
+ def set_printer_settings(self, paper_size, orientation):
538
+ """Set printer settings """
539
+
540
+ self.page_setup.paperSize = paper_size
541
+ self.page_setup.orientation = orientation
542
+
543
+
544
+ def add_data_validation(self, data_validation):
545
+ """ Add a data-validation object to the sheet. The data-validation
546
+ object defines the type of data-validation to be applied and the
547
+ cell or range of cells it should apply to.
548
+ """
549
+ self.data_validations.append(data_validation)
550
+
551
+
552
+ def add_chart(self, chart, anchor=None):
553
+ """
554
+ Add a chart to the sheet
555
+ Optionally provide a cell for the top-left anchor
556
+ """
557
+ if anchor is not None:
558
+ chart.anchor = anchor
559
+ self._charts.append(chart)
560
+
561
+
562
+ def add_image(self, img, anchor=None):
563
+ """
564
+ Add an image to the sheet.
565
+ Optionally provide a cell for the top-left anchor
566
+ """
567
+ if anchor is not None:
568
+ img.anchor = anchor
569
+ self._images.append(img)
570
+
571
+
572
+ def add_table(self, table):
573
+ """
574
+ Check for duplicate name in definedNames and other worksheet tables
575
+ before adding table.
576
+ """
577
+
578
+ if self.parent._duplicate_name(table.name):
579
+ raise ValueError("Table with name {0} already exists".format(table.name))
580
+ if not hasattr(self, "_get_cell"):
581
+ warn("In write-only mode you must add table columns manually")
582
+ self._tables.add(table)
583
+
584
+
585
+ @property
586
+ def tables(self):
587
+ return self._tables
588
+
589
+
590
+ def add_pivot(self, pivot):
591
+ self._pivots.append(pivot)
592
+
593
+
594
+ def merge_cells(self, range_string=None, start_row=None, start_column=None, end_row=None, end_column=None):
595
+ """ Set merge on a cell range. Range is a cell range (e.g. A1:E1) """
596
+ if range_string is None:
597
+ cr = CellRange(range_string=range_string, min_col=start_column, min_row=start_row,
598
+ max_col=end_column, max_row=end_row)
599
+ range_string = cr.coord
600
+ mcr = MergedCellRange(self, range_string)
601
+ self.merged_cells.add(mcr)
602
+ self._clean_merge_range(mcr)
603
+
604
+
605
+ def _clean_merge_range(self, mcr):
606
+ """
607
+ Remove all but the top left-cell from a range of merged cells
608
+ and recreate the lost border information.
609
+ Borders are then applied
610
+ """
611
+ cells = mcr.cells
612
+ next(cells) # skip first cell
613
+ for row, col in cells:
614
+ self._cells[row, col] = MergedCell(self, row, col)
615
+ mcr.format()
616
+
617
+
618
+ @property
619
+ @deprecated("Use ws.merged_cells.ranges")
620
+ def merged_cell_ranges(self):
621
+ """Return a copy of cell ranges"""
622
+ return self.merged_cells.ranges[:]
623
+
624
+
625
+ def unmerge_cells(self, range_string=None, start_row=None, start_column=None, end_row=None, end_column=None):
626
+ """ Remove merge on a cell range. Range is a cell range (e.g. A1:E1) """
627
+ cr = CellRange(range_string=range_string, min_col=start_column, min_row=start_row,
628
+ max_col=end_column, max_row=end_row)
629
+
630
+ if cr.coord not in self.merged_cells:
631
+ raise ValueError("Cell range {0} is not merged".format(cr.coord))
632
+
633
+ self.merged_cells.remove(cr)
634
+
635
+ cells = cr.cells
636
+ next(cells) # skip first cell
637
+ for row, col in cells:
638
+ del self._cells[(row, col)]
639
+
640
+
641
+ def append(self, iterable):
642
+ """Appends a group of values at the bottom of the current sheet.
643
+
644
+ * If it's a list: all values are added in order, starting from the first column
645
+ * If it's a dict: values are assigned to the columns indicated by the keys (numbers or letters)
646
+
647
+ :param iterable: list, range or generator, or dict containing values to append
648
+ :type iterable: list|tuple|range|generator or dict
649
+
650
+ Usage:
651
+
652
+ * append(['This is A1', 'This is B1', 'This is C1'])
653
+ * **or** append({'A' : 'This is A1', 'C' : 'This is C1'})
654
+ * **or** append({1 : 'This is A1', 3 : 'This is C1'})
655
+
656
+ :raise: TypeError when iterable is neither a list/tuple nor a dict
657
+
658
+ """
659
+ row_idx = self._current_row + 1
660
+
661
+ if (isinstance(iterable, (list, tuple, range))
662
+ or isgenerator(iterable)):
663
+ for col_idx, content in enumerate(iterable, 1):
664
+ if isinstance(content, Cell):
665
+ # compatible with write-only mode
666
+ cell = content
667
+ if cell.parent and cell.parent != self:
668
+ raise ValueError("Cells cannot be copied from other worksheets")
669
+ cell.parent = self
670
+ cell.column = col_idx
671
+ cell.row = row_idx
672
+ else:
673
+ cell = Cell(self, row=row_idx, column=col_idx, value=content)
674
+ self._cells[(row_idx, col_idx)] = cell
675
+
676
+ elif isinstance(iterable, dict):
677
+ for col_idx, content in iterable.items():
678
+ if isinstance(col_idx, str):
679
+ col_idx = column_index_from_string(col_idx)
680
+ cell = Cell(self, row=row_idx, column=col_idx, value=content)
681
+ self._cells[(row_idx, col_idx)] = cell
682
+
683
+ else:
684
+ self._invalid_row(iterable)
685
+
686
+ self._current_row = row_idx
687
+
688
+
689
+ def _move_cells(self, min_row=None, min_col=None, offset=0, row_or_col="row"):
690
+ """
691
+ Move either rows or columns around by the offset
692
+ """
693
+ reverse = offset > 0 # start at the end if inserting
694
+ row_offset = 0
695
+ col_offset = 0
696
+
697
+ # need to make affected ranges contiguous
698
+ if row_or_col == 'row':
699
+ cells = self.iter_rows(min_row=min_row)
700
+ row_offset = offset
701
+ key = 0
702
+ else:
703
+ cells = self.iter_cols(min_col=min_col)
704
+ col_offset = offset
705
+ key = 1
706
+ cells = list(cells)
707
+
708
+ for row, column in sorted(self._cells, key=itemgetter(key), reverse=reverse):
709
+ if min_row and row < min_row:
710
+ continue
711
+ elif min_col and column < min_col:
712
+ continue
713
+
714
+ self._move_cell(row, column, row_offset, col_offset)
715
+
716
+
717
+ def insert_rows(self, idx, amount=1):
718
+ """
719
+ Insert row or rows before row==idx
720
+ """
721
+ self._move_cells(min_row=idx, offset=amount, row_or_col="row")
722
+ self._current_row = self.max_row
723
+
724
+
725
+ def insert_cols(self, idx, amount=1):
726
+ """
727
+ Insert column or columns before col==idx
728
+ """
729
+ self._move_cells(min_col=idx, offset=amount, row_or_col="column")
730
+
731
+
732
+ def delete_rows(self, idx, amount=1):
733
+ """
734
+ Delete row or rows from row==idx
735
+ """
736
+
737
+ remainder = _gutter(idx, amount, self.max_row)
738
+
739
+ self._move_cells(min_row=idx+amount, offset=-amount, row_or_col="row")
740
+
741
+ # calculating min and max col is an expensive operation, do it only once
742
+ min_col = self.min_column
743
+ max_col = self.max_column + 1
744
+ for row in remainder:
745
+ for col in range(min_col, max_col):
746
+ if (row, col) in self._cells:
747
+ del self._cells[row, col]
748
+ self._current_row = self.max_row
749
+ if not self._cells:
750
+ self._current_row = 0
751
+
752
+
753
+ def delete_cols(self, idx, amount=1):
754
+ """
755
+ Delete column or columns from col==idx
756
+ """
757
+
758
+ remainder = _gutter(idx, amount, self.max_column)
759
+
760
+ self._move_cells(min_col=idx+amount, offset=-amount, row_or_col="column")
761
+
762
+ # calculating min and max row is an expensive operation, do it only once
763
+ min_row = self.min_row
764
+ max_row = self.max_row + 1
765
+ for col in remainder:
766
+ for row in range(min_row, max_row):
767
+ if (row, col) in self._cells:
768
+ del self._cells[row, col]
769
+
770
+
771
+ def move_range(self, cell_range, rows=0, cols=0, translate=False):
772
+ """
773
+ Move a cell range by the number of rows and/or columns:
774
+ down if rows > 0 and up if rows < 0
775
+ right if cols > 0 and left if cols < 0
776
+ Existing cells will be overwritten.
777
+ Formulae and references will not be updated.
778
+ """
779
+ if isinstance(cell_range, str):
780
+ cell_range = CellRange(cell_range)
781
+ if not isinstance(cell_range, CellRange):
782
+ raise ValueError("Only CellRange objects can be moved")
783
+ if not rows and not cols:
784
+ return
785
+
786
+ down = rows > 0
787
+ right = cols > 0
788
+
789
+ if rows:
790
+ cells = sorted(cell_range.rows, reverse=down)
791
+ else:
792
+ cells = sorted(cell_range.cols, reverse=right)
793
+
794
+ for row, col in chain.from_iterable(cells):
795
+ self._move_cell(row, col, rows, cols, translate)
796
+
797
+ # rebase moved range
798
+ cell_range.shift(row_shift=rows, col_shift=cols)
799
+
800
+
801
+ def _move_cell(self, row, column, row_offset, col_offset, translate=False):
802
+ """
803
+ Move a cell from one place to another.
804
+ Delete at old index
805
+ Rebase coordinate
806
+ """
807
+ cell = self._get_cell(row, column)
808
+ new_row = cell.row + row_offset
809
+ new_col = cell.column + col_offset
810
+ self._cells[new_row, new_col] = cell
811
+ del self._cells[(cell.row, cell.column)]
812
+ cell.row = new_row
813
+ cell.column = new_col
814
+ if translate and cell.data_type == "f":
815
+ t = Translator(cell.value, cell.coordinate)
816
+ cell.value = t.translate_formula(row_delta=row_offset, col_delta=col_offset)
817
+
818
+
819
+ def _invalid_row(self, iterable):
820
+ raise TypeError('Value must be a list, tuple, range or generator, or a dict. Supplied value is {0}'.format(
821
+ type(iterable))
822
+ )
823
+
824
+
825
+ def _add_column(self):
826
+ """Dimension factory for column information"""
827
+
828
+ return ColumnDimension(self)
829
+
830
+ def _add_row(self):
831
+ """Dimension factory for row information"""
832
+
833
+ return RowDimension(self)
834
+
835
+
836
+ @property
837
+ def print_title_rows(self):
838
+ """Rows to be printed at the top of every page (ex: '1:3')"""
839
+ if self._print_rows:
840
+ return str(self._print_rows)
841
+
842
+
843
+ @print_title_rows.setter
844
+ def print_title_rows(self, rows):
845
+ """
846
+ Set rows to be printed on the top of every page
847
+ format `1:3`
848
+ """
849
+ if rows is not None:
850
+ self._print_rows = RowRange(rows)
851
+
852
+
853
+ @property
854
+ def print_title_cols(self):
855
+ """Columns to be printed at the left side of every page (ex: 'A:C')"""
856
+ if self._print_cols:
857
+ return str(self._print_cols)
858
+
859
+
860
+ @print_title_cols.setter
861
+ def print_title_cols(self, cols):
862
+ """
863
+ Set cols to be printed on the left of every page
864
+ format ``A:C`
865
+ """
866
+ if cols is not None:
867
+ self._print_cols = ColRange(cols)
868
+
869
+
870
+ @property
871
+ def print_titles(self):
872
+ titles = PrintTitles(cols=self._print_cols, rows=self._print_rows, title=self.title)
873
+ return str(titles)
874
+
875
+
876
+ @property
877
+ def print_area(self):
878
+ """
879
+ The print area for the worksheet, or None if not set. To set, supply a range
880
+ like 'A1:D4' or a list of ranges.
881
+ """
882
+ self._print_area.title = self.title
883
+ return str(self._print_area)
884
+
885
+
886
+ @print_area.setter
887
+ def print_area(self, value):
888
+ """
889
+ Range of cells in the form A1:D4 or list of ranges. Print area can be cleared
890
+ by passing `None` or an empty list
891
+ """
892
+ if not value:
893
+ self._print_area = PrintArea()
894
+ elif isinstance(value, str):
895
+ self._print_area = PrintArea.from_string(value)
896
+ elif hasattr(value, "__iter__"):
897
+ self._print_area = PrintArea.from_string(",".join(value))
898
+
899
+
900
+ def _gutter(idx, offset, max_val):
901
+ """
902
+ When deleting rows and columns are deleted we rely on overwriting.
903
+ This may not be the case for a large offset on small set of cells:
904
+ range(cells_to_delete) > range(cell_to_be_moved)
905
+ """
906
+ gutter = range(max(max_val+1-offset, idx), min(idx+offset, max_val)+1)
907
+ return gutter