@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.
- package/CHANGELOG.md +38 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/collector-runtime.js +56 -1
- package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
- package/lib/data-collector/catalog-taxonomy.js +33 -0
- package/lib/data-collector/tools.js +7 -7
- package/lib/python-runtime/errors.d.ts +1 -1
- package/lib/python-runtime/errors.js +2 -0
- package/lib/python-runtime/manager.d.ts +28 -1
- package/lib/python-runtime/manager.js +141 -5
- package/lib/python-runtime/probe.d.ts +24 -0
- package/lib/python-runtime/probe.js +66 -50
- package/lib/sources/csindex-http.d.ts +4 -0
- package/lib/sources/csindex-http.js +233 -0
- package/lib/sources/eastmoney-http.js +1504 -1
- package/lib/sources/fuyao-rest.js +168 -8
- package/lib/sources/official-http.d.ts +4 -0
- package/lib/sources/official-http.js +477 -0
- package/lib/sources/python-remote.d.ts +25 -0
- package/lib/sources/python-remote.js +461 -0
- package/lib/sources/sina-http.d.ts +2 -0
- package/lib/sources/sina-http.js +484 -0
- package/lib/sources/tencent-http.js +23 -8
- package/lib/sources/ths-http.d.ts +2 -0
- package/lib/sources/ths-http.js +514 -0
- package/lib/time/tools.js +19 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +7 -0
- package/lib/web-retriever/sources.js +46 -21
- package/lib/web-retriever/throttle.d.ts +8 -0
- package/lib/web-retriever/throttle.js +13 -0
- package/lib/web-retriever/tools.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +1 -1
- package/preset/capital-generation/agent.patch.yml +7 -5
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
- package/python/scripts/baostock_stock_basic.py +129 -0
- package/python/scripts/baostock_valuation_history.py +141 -0
- package/python/scripts/pbc_social_financing.py +291 -0
- package/python/vendor/baostock/LICENSE +19 -0
- package/python/vendor/baostock/__init__.py +42 -0
- package/python/vendor/baostock/common/__init__.py +0 -0
- package/python/vendor/baostock/common/contants.py +189 -0
- package/python/vendor/baostock/common/context.py +4 -0
- package/python/vendor/baostock/corpreport/__init__.py +0 -0
- package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
- package/python/vendor/baostock/data/__init__.py +0 -0
- package/python/vendor/baostock/data/messageheader.py +17 -0
- package/python/vendor/baostock/data/msg.py +21 -0
- package/python/vendor/baostock/data/resultset.py +200 -0
- package/python/vendor/baostock/demo/__init__.py +0 -0
- package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
- package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
- package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
- package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
- package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
- package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
- package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
- package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
- package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
- package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
- package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
- package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
- package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
- package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
- package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
- package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
- package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
- package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
- package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
- package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
- package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
- package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
- package/python/vendor/baostock/evaluation/__init__.py +0 -0
- package/python/vendor/baostock/evaluation/season_index.py +758 -0
- package/python/vendor/baostock/login/__init__.py +0 -0
- package/python/vendor/baostock/login/loginout.py +230 -0
- package/python/vendor/baostock/macroscopic/__init__.py +0 -0
- package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
- package/python/vendor/baostock/metadata/__init__.py +0 -0
- package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
- package/python/vendor/baostock/security/__init__.py +0 -0
- package/python/vendor/baostock/security/history.py +265 -0
- package/python/vendor/baostock/security/sectorinfo.py +1024 -0
- package/python/vendor/baostock/util/__init__.py +0 -0
- package/python/vendor/baostock/util/socketutil.py +97 -0
- package/python/vendor/baostock/util/stringutil.py +83 -0
- package/python/vendor/et_xmlfile/LICENSE +23 -0
- package/python/vendor/et_xmlfile/LICENSE.python +298 -0
- package/python/vendor/et_xmlfile/__init__.py +8 -0
- package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
- package/python/vendor/et_xmlfile/xmlfile.py +158 -0
- package/python/vendor/openpyxl/LICENSE +23 -0
- package/python/vendor/openpyxl/__init__.py +19 -0
- package/python/vendor/openpyxl/_constants.py +13 -0
- package/python/vendor/openpyxl/cell/__init__.py +4 -0
- package/python/vendor/openpyxl/cell/_writer.py +136 -0
- package/python/vendor/openpyxl/cell/cell.py +332 -0
- package/python/vendor/openpyxl/cell/read_only.py +136 -0
- package/python/vendor/openpyxl/cell/rich_text.py +202 -0
- package/python/vendor/openpyxl/cell/text.py +184 -0
- package/python/vendor/openpyxl/chart/_3d.py +105 -0
- package/python/vendor/openpyxl/chart/__init__.py +19 -0
- package/python/vendor/openpyxl/chart/_chart.py +199 -0
- package/python/vendor/openpyxl/chart/area_chart.py +106 -0
- package/python/vendor/openpyxl/chart/axis.py +401 -0
- package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
- package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
- package/python/vendor/openpyxl/chart/chartspace.py +195 -0
- package/python/vendor/openpyxl/chart/data_source.py +246 -0
- package/python/vendor/openpyxl/chart/descriptors.py +43 -0
- package/python/vendor/openpyxl/chart/error_bar.py +62 -0
- package/python/vendor/openpyxl/chart/label.py +127 -0
- package/python/vendor/openpyxl/chart/layout.py +74 -0
- package/python/vendor/openpyxl/chart/legend.py +75 -0
- package/python/vendor/openpyxl/chart/line_chart.py +129 -0
- package/python/vendor/openpyxl/chart/marker.py +90 -0
- package/python/vendor/openpyxl/chart/picture.py +35 -0
- package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
- package/python/vendor/openpyxl/chart/pivot.py +65 -0
- package/python/vendor/openpyxl/chart/plotarea.py +162 -0
- package/python/vendor/openpyxl/chart/print_settings.py +57 -0
- package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
- package/python/vendor/openpyxl/chart/reader.py +32 -0
- package/python/vendor/openpyxl/chart/reference.py +124 -0
- package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
- package/python/vendor/openpyxl/chart/series.py +197 -0
- package/python/vendor/openpyxl/chart/series_factory.py +41 -0
- package/python/vendor/openpyxl/chart/shapes.py +89 -0
- package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
- package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
- package/python/vendor/openpyxl/chart/text.py +78 -0
- package/python/vendor/openpyxl/chart/title.py +76 -0
- package/python/vendor/openpyxl/chart/trendline.py +98 -0
- package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
- package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
- package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
- package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
- package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
- package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
- package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
- package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
- package/python/vendor/openpyxl/chartsheet/views.py +51 -0
- package/python/vendor/openpyxl/comments/__init__.py +4 -0
- package/python/vendor/openpyxl/comments/author.py +21 -0
- package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
- package/python/vendor/openpyxl/comments/comments.py +62 -0
- package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
- package/python/vendor/openpyxl/compat/__init__.py +54 -0
- package/python/vendor/openpyxl/compat/abc.py +8 -0
- package/python/vendor/openpyxl/compat/numbers.py +43 -0
- package/python/vendor/openpyxl/compat/product.py +17 -0
- package/python/vendor/openpyxl/compat/singleton.py +40 -0
- package/python/vendor/openpyxl/compat/strings.py +25 -0
- package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
- package/python/vendor/openpyxl/descriptors/base.py +272 -0
- package/python/vendor/openpyxl/descriptors/container.py +41 -0
- package/python/vendor/openpyxl/descriptors/excel.py +112 -0
- package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
- package/python/vendor/openpyxl/descriptors/nested.py +129 -0
- package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
- package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
- package/python/vendor/openpyxl/descriptors/slots.py +18 -0
- package/python/vendor/openpyxl/drawing/__init__.py +4 -0
- package/python/vendor/openpyxl/drawing/colors.py +435 -0
- package/python/vendor/openpyxl/drawing/connector.py +144 -0
- package/python/vendor/openpyxl/drawing/drawing.py +92 -0
- package/python/vendor/openpyxl/drawing/effect.py +407 -0
- package/python/vendor/openpyxl/drawing/fill.py +425 -0
- package/python/vendor/openpyxl/drawing/geometry.py +584 -0
- package/python/vendor/openpyxl/drawing/graphic.py +177 -0
- package/python/vendor/openpyxl/drawing/image.py +65 -0
- package/python/vendor/openpyxl/drawing/line.py +144 -0
- package/python/vendor/openpyxl/drawing/picture.py +144 -0
- package/python/vendor/openpyxl/drawing/properties.py +174 -0
- package/python/vendor/openpyxl/drawing/relation.py +17 -0
- package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
- package/python/vendor/openpyxl/drawing/text.py +717 -0
- package/python/vendor/openpyxl/drawing/xdr.py +33 -0
- package/python/vendor/openpyxl/formatting/__init__.py +3 -0
- package/python/vendor/openpyxl/formatting/formatting.py +114 -0
- package/python/vendor/openpyxl/formatting/rule.py +291 -0
- package/python/vendor/openpyxl/formula/__init__.py +3 -0
- package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
- package/python/vendor/openpyxl/formula/translate.py +166 -0
- package/python/vendor/openpyxl/packaging/__init__.py +3 -0
- package/python/vendor/openpyxl/packaging/core.py +115 -0
- package/python/vendor/openpyxl/packaging/custom.py +289 -0
- package/python/vendor/openpyxl/packaging/extended.py +137 -0
- package/python/vendor/openpyxl/packaging/interface.py +56 -0
- package/python/vendor/openpyxl/packaging/manifest.py +194 -0
- package/python/vendor/openpyxl/packaging/relationship.py +158 -0
- package/python/vendor/openpyxl/packaging/workbook.py +185 -0
- package/python/vendor/openpyxl/pivot/__init__.py +1 -0
- package/python/vendor/openpyxl/pivot/cache.py +965 -0
- package/python/vendor/openpyxl/pivot/fields.py +326 -0
- package/python/vendor/openpyxl/pivot/record.py +111 -0
- package/python/vendor/openpyxl/pivot/table.py +1261 -0
- package/python/vendor/openpyxl/reader/__init__.py +1 -0
- package/python/vendor/openpyxl/reader/drawings.py +71 -0
- package/python/vendor/openpyxl/reader/excel.py +349 -0
- package/python/vendor/openpyxl/reader/strings.py +44 -0
- package/python/vendor/openpyxl/reader/workbook.py +133 -0
- package/python/vendor/openpyxl/styles/__init__.py +11 -0
- package/python/vendor/openpyxl/styles/alignment.py +62 -0
- package/python/vendor/openpyxl/styles/borders.py +103 -0
- package/python/vendor/openpyxl/styles/builtins.py +1397 -0
- package/python/vendor/openpyxl/styles/cell_style.py +206 -0
- package/python/vendor/openpyxl/styles/colors.py +172 -0
- package/python/vendor/openpyxl/styles/differential.py +95 -0
- package/python/vendor/openpyxl/styles/fills.py +224 -0
- package/python/vendor/openpyxl/styles/fonts.py +113 -0
- package/python/vendor/openpyxl/styles/named_styles.py +282 -0
- package/python/vendor/openpyxl/styles/numbers.py +200 -0
- package/python/vendor/openpyxl/styles/protection.py +17 -0
- package/python/vendor/openpyxl/styles/proxy.py +62 -0
- package/python/vendor/openpyxl/styles/styleable.py +151 -0
- package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
- package/python/vendor/openpyxl/styles/table.py +94 -0
- package/python/vendor/openpyxl/utils/__init__.py +17 -0
- package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
- package/python/vendor/openpyxl/utils/cell.py +240 -0
- package/python/vendor/openpyxl/utils/dataframe.py +87 -0
- package/python/vendor/openpyxl/utils/datetime.py +140 -0
- package/python/vendor/openpyxl/utils/escape.py +43 -0
- package/python/vendor/openpyxl/utils/exceptions.py +34 -0
- package/python/vendor/openpyxl/utils/formulas.py +24 -0
- package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
- package/python/vendor/openpyxl/utils/inference.py +60 -0
- package/python/vendor/openpyxl/utils/protection.py +22 -0
- package/python/vendor/openpyxl/utils/units.py +108 -0
- package/python/vendor/openpyxl/workbook/__init__.py +4 -0
- package/python/vendor/openpyxl/workbook/_writer.py +197 -0
- package/python/vendor/openpyxl/workbook/child.py +166 -0
- package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
- package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
- package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
- package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
- package/python/vendor/openpyxl/workbook/function_group.py +36 -0
- package/python/vendor/openpyxl/workbook/properties.py +151 -0
- package/python/vendor/openpyxl/workbook/protection.py +163 -0
- package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
- package/python/vendor/openpyxl/workbook/views.py +155 -0
- package/python/vendor/openpyxl/workbook/web.py +98 -0
- package/python/vendor/openpyxl/workbook/workbook.py +438 -0
- package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
- package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
- package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
- package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
- package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
- package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
- package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
- package/python/vendor/openpyxl/worksheet/controls.py +107 -0
- package/python/vendor/openpyxl/worksheet/copier.py +70 -0
- package/python/vendor/openpyxl/worksheet/custom.py +35 -0
- package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
- package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
- package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
- package/python/vendor/openpyxl/worksheet/errors.py +93 -0
- package/python/vendor/openpyxl/worksheet/filters.py +486 -0
- package/python/vendor/openpyxl/worksheet/formula.py +51 -0
- package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
- package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
- package/python/vendor/openpyxl/worksheet/merge.py +141 -0
- package/python/vendor/openpyxl/worksheet/ole.py +133 -0
- package/python/vendor/openpyxl/worksheet/page.py +174 -0
- package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
- package/python/vendor/openpyxl/worksheet/picture.py +8 -0
- package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
- package/python/vendor/openpyxl/worksheet/properties.py +97 -0
- package/python/vendor/openpyxl/worksheet/protection.py +120 -0
- package/python/vendor/openpyxl/worksheet/related.py +17 -0
- package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
- package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
- package/python/vendor/openpyxl/worksheet/table.py +385 -0
- package/python/vendor/openpyxl/worksheet/views.py +155 -0
- package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
- package/python/vendor/openpyxl/writer/__init__.py +1 -0
- package/python/vendor/openpyxl/writer/excel.py +295 -0
- package/python/vendor/openpyxl/writer/theme.py +291 -0
- package/python/vendor/openpyxl/xml/__init__.py +42 -0
- package/python/vendor/openpyxl/xml/constants.py +129 -0
- package/python/vendor/openpyxl/xml/functions.py +87 -0
- package/watchlist/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
from io import BytesIO
|
|
6
|
+
from warnings import warn
|
|
7
|
+
|
|
8
|
+
from openpyxl.xml.functions import fromstring
|
|
9
|
+
from openpyxl.xml.constants import IMAGE_NS
|
|
10
|
+
from openpyxl.packaging.relationship import (
|
|
11
|
+
get_rel,
|
|
12
|
+
get_rels_path,
|
|
13
|
+
get_dependents,
|
|
14
|
+
)
|
|
15
|
+
from openpyxl.drawing.spreadsheet_drawing import SpreadsheetDrawing
|
|
16
|
+
from openpyxl.drawing.image import Image, PILImage
|
|
17
|
+
from openpyxl.chart.chartspace import ChartSpace
|
|
18
|
+
from openpyxl.chart.reader import read_chart
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def find_images(archive, path):
|
|
22
|
+
"""
|
|
23
|
+
Given the path to a drawing file extract charts and images
|
|
24
|
+
|
|
25
|
+
Ignore errors due to unsupported parts of DrawingML
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
src = archive.read(path)
|
|
29
|
+
tree = fromstring(src)
|
|
30
|
+
try:
|
|
31
|
+
drawing = SpreadsheetDrawing.from_tree(tree)
|
|
32
|
+
except TypeError:
|
|
33
|
+
warn("DrawingML support is incomplete and limited to charts and images only. Shapes and drawings will be lost.")
|
|
34
|
+
return [], []
|
|
35
|
+
|
|
36
|
+
rels_path = get_rels_path(path)
|
|
37
|
+
deps = []
|
|
38
|
+
if rels_path in archive.namelist():
|
|
39
|
+
deps = get_dependents(archive, rels_path)
|
|
40
|
+
|
|
41
|
+
charts = []
|
|
42
|
+
for rel in drawing._chart_rels:
|
|
43
|
+
try:
|
|
44
|
+
cs = get_rel(archive, deps, rel.id, ChartSpace)
|
|
45
|
+
except TypeError as e:
|
|
46
|
+
warn(f"Unable to read chart {rel.id} from {path} {e}")
|
|
47
|
+
continue
|
|
48
|
+
chart = read_chart(cs)
|
|
49
|
+
chart.anchor = rel.anchor
|
|
50
|
+
charts.append(chart)
|
|
51
|
+
|
|
52
|
+
images = []
|
|
53
|
+
if not PILImage: # Pillow not installed, drop images
|
|
54
|
+
return charts, images
|
|
55
|
+
|
|
56
|
+
for rel in drawing._blip_rels:
|
|
57
|
+
dep = deps.get(rel.embed)
|
|
58
|
+
if dep.Type == IMAGE_NS:
|
|
59
|
+
try:
|
|
60
|
+
image = Image(BytesIO(archive.read(dep.target)))
|
|
61
|
+
except OSError:
|
|
62
|
+
msg = "The image {0} will be removed because it cannot be read".format(dep.target)
|
|
63
|
+
warn(msg)
|
|
64
|
+
continue
|
|
65
|
+
if image.format.upper() == "WMF": # cannot save
|
|
66
|
+
msg = "{0} image format is not supported so the image is being dropped".format(image.format)
|
|
67
|
+
warn(msg)
|
|
68
|
+
continue
|
|
69
|
+
image.anchor = rel.anchor
|
|
70
|
+
images.append(image)
|
|
71
|
+
return charts, images
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
"""Read an xlsx file into Python"""
|
|
5
|
+
|
|
6
|
+
# Python stdlib imports
|
|
7
|
+
from zipfile import ZipFile, ZIP_DEFLATED
|
|
8
|
+
from io import BytesIO
|
|
9
|
+
import os.path
|
|
10
|
+
import warnings
|
|
11
|
+
|
|
12
|
+
from openpyxl.pivot.table import TableDefinition
|
|
13
|
+
|
|
14
|
+
# Allow blanket setting of KEEP_VBA for testing
|
|
15
|
+
try:
|
|
16
|
+
from ..tests import KEEP_VBA
|
|
17
|
+
except ImportError:
|
|
18
|
+
KEEP_VBA = False
|
|
19
|
+
|
|
20
|
+
# package imports
|
|
21
|
+
from openpyxl.utils.exceptions import InvalidFileException
|
|
22
|
+
from openpyxl.xml.constants import (
|
|
23
|
+
ARC_CORE,
|
|
24
|
+
ARC_CUSTOM,
|
|
25
|
+
ARC_CONTENT_TYPES,
|
|
26
|
+
ARC_WORKBOOK,
|
|
27
|
+
ARC_THEME,
|
|
28
|
+
COMMENTS_NS,
|
|
29
|
+
SHARED_STRINGS,
|
|
30
|
+
XLTM,
|
|
31
|
+
XLTX,
|
|
32
|
+
XLSM,
|
|
33
|
+
XLSX,
|
|
34
|
+
)
|
|
35
|
+
from openpyxl.cell import MergedCell
|
|
36
|
+
from openpyxl.comments.comment_sheet import CommentSheet
|
|
37
|
+
|
|
38
|
+
from .strings import read_string_table, read_rich_text
|
|
39
|
+
from .workbook import WorkbookParser
|
|
40
|
+
from openpyxl.styles.stylesheet import apply_stylesheet
|
|
41
|
+
|
|
42
|
+
from openpyxl.packaging.core import DocumentProperties
|
|
43
|
+
from openpyxl.packaging.custom import CustomPropertyList
|
|
44
|
+
from openpyxl.packaging.manifest import Manifest, Override
|
|
45
|
+
|
|
46
|
+
from openpyxl.packaging.relationship import (
|
|
47
|
+
RelationshipList,
|
|
48
|
+
get_dependents,
|
|
49
|
+
get_rels_path,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
from openpyxl.worksheet._read_only import ReadOnlyWorksheet
|
|
53
|
+
from openpyxl.worksheet._reader import WorksheetReader
|
|
54
|
+
from openpyxl.chartsheet import Chartsheet
|
|
55
|
+
from openpyxl.worksheet.table import Table
|
|
56
|
+
from openpyxl.drawing.spreadsheet_drawing import SpreadsheetDrawing
|
|
57
|
+
|
|
58
|
+
from openpyxl.xml.functions import fromstring
|
|
59
|
+
|
|
60
|
+
from .drawings import find_images
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
SUPPORTED_FORMATS = ('.xlsx', '.xlsm', '.xltx', '.xltm')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _validate_archive(filename):
|
|
67
|
+
"""
|
|
68
|
+
Does a first check whether filename is a string or a file-like
|
|
69
|
+
object. If it is a string representing a filename, a check is done
|
|
70
|
+
for supported formats by checking the given file-extension. If the
|
|
71
|
+
file-extension is not in SUPPORTED_FORMATS an InvalidFileException
|
|
72
|
+
will raised. Otherwise the filename (resp. file-like object) will
|
|
73
|
+
forwarded to zipfile.ZipFile returning a ZipFile-Instance.
|
|
74
|
+
"""
|
|
75
|
+
is_file_like = hasattr(filename, 'read')
|
|
76
|
+
if not is_file_like:
|
|
77
|
+
file_format = os.path.splitext(filename)[-1].lower()
|
|
78
|
+
if file_format not in SUPPORTED_FORMATS:
|
|
79
|
+
if file_format == '.xls':
|
|
80
|
+
msg = ('openpyxl does not support the old .xls file format, '
|
|
81
|
+
'please use xlrd to read this file, or convert it to '
|
|
82
|
+
'the more recent .xlsx file format.')
|
|
83
|
+
elif file_format == '.xlsb':
|
|
84
|
+
msg = ('openpyxl does not support binary format .xlsb, '
|
|
85
|
+
'please convert this file to .xlsx format if you want '
|
|
86
|
+
'to open it with openpyxl')
|
|
87
|
+
else:
|
|
88
|
+
msg = ('openpyxl does not support %s file format, '
|
|
89
|
+
'please check you can open '
|
|
90
|
+
'it with Excel first. '
|
|
91
|
+
'Supported formats are: %s') % (file_format,
|
|
92
|
+
','.join(SUPPORTED_FORMATS))
|
|
93
|
+
raise InvalidFileException(msg)
|
|
94
|
+
|
|
95
|
+
archive = ZipFile(filename, 'r')
|
|
96
|
+
return archive
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _find_workbook_part(package):
|
|
100
|
+
workbook_types = [XLTM, XLTX, XLSM, XLSX]
|
|
101
|
+
for ct in workbook_types:
|
|
102
|
+
part = package.find(ct)
|
|
103
|
+
if part:
|
|
104
|
+
return part
|
|
105
|
+
|
|
106
|
+
# some applications reassign the default for application/xml
|
|
107
|
+
defaults = {p.ContentType for p in package.Default}
|
|
108
|
+
workbook_type = defaults & set(workbook_types)
|
|
109
|
+
if workbook_type:
|
|
110
|
+
return Override("/" + ARC_WORKBOOK, workbook_type.pop())
|
|
111
|
+
|
|
112
|
+
raise IOError("File contains no valid workbook part")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class ExcelReader:
|
|
116
|
+
|
|
117
|
+
"""
|
|
118
|
+
Read an Excel package and dispatch the contents to the relevant modules
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def __init__(self, fn, read_only=False, keep_vba=KEEP_VBA,
|
|
122
|
+
data_only=False, keep_links=True, rich_text=False):
|
|
123
|
+
self.archive = _validate_archive(fn)
|
|
124
|
+
self.valid_files = self.archive.namelist()
|
|
125
|
+
self.read_only = read_only
|
|
126
|
+
self.keep_vba = keep_vba
|
|
127
|
+
self.data_only = data_only
|
|
128
|
+
self.keep_links = keep_links
|
|
129
|
+
self.rich_text = rich_text
|
|
130
|
+
self.shared_strings = []
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def read_manifest(self):
|
|
134
|
+
src = self.archive.read(ARC_CONTENT_TYPES)
|
|
135
|
+
root = fromstring(src)
|
|
136
|
+
self.package = Manifest.from_tree(root)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def read_strings(self):
|
|
140
|
+
ct = self.package.find(SHARED_STRINGS)
|
|
141
|
+
reader = read_string_table
|
|
142
|
+
if self.rich_text:
|
|
143
|
+
reader = read_rich_text
|
|
144
|
+
if ct is not None:
|
|
145
|
+
strings_path = ct.PartName[1:]
|
|
146
|
+
with self.archive.open(strings_path,) as src:
|
|
147
|
+
self.shared_strings = reader(src)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def read_workbook(self):
|
|
151
|
+
wb_part = _find_workbook_part(self.package)
|
|
152
|
+
self.parser = WorkbookParser(self.archive, wb_part.PartName[1:], keep_links=self.keep_links)
|
|
153
|
+
self.parser.parse()
|
|
154
|
+
wb = self.parser.wb
|
|
155
|
+
wb._sheets = []
|
|
156
|
+
wb._data_only = self.data_only
|
|
157
|
+
wb._read_only = self.read_only
|
|
158
|
+
wb.template = wb_part.ContentType in (XLTX, XLTM)
|
|
159
|
+
|
|
160
|
+
# If are going to preserve the vba then attach a copy of the archive to the
|
|
161
|
+
# workbook so that is available for the save.
|
|
162
|
+
if self.keep_vba:
|
|
163
|
+
wb.vba_archive = ZipFile(BytesIO(), 'a', ZIP_DEFLATED)
|
|
164
|
+
for name in self.valid_files:
|
|
165
|
+
wb.vba_archive.writestr(name, self.archive.read(name))
|
|
166
|
+
|
|
167
|
+
if self.read_only:
|
|
168
|
+
wb._archive = self.archive
|
|
169
|
+
|
|
170
|
+
self.wb = wb
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def read_properties(self):
|
|
174
|
+
if ARC_CORE in self.valid_files:
|
|
175
|
+
src = fromstring(self.archive.read(ARC_CORE))
|
|
176
|
+
self.wb.properties = DocumentProperties.from_tree(src)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def read_custom(self):
|
|
180
|
+
if ARC_CUSTOM in self.valid_files:
|
|
181
|
+
src = fromstring(self.archive.read(ARC_CUSTOM))
|
|
182
|
+
self.wb.custom_doc_props = CustomPropertyList.from_tree(src)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def read_theme(self):
|
|
186
|
+
if ARC_THEME in self.valid_files:
|
|
187
|
+
self.wb.loaded_theme = self.archive.read(ARC_THEME)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def read_chartsheet(self, sheet, rel):
|
|
191
|
+
sheet_path = rel.target
|
|
192
|
+
rels_path = get_rels_path(sheet_path)
|
|
193
|
+
rels = []
|
|
194
|
+
if rels_path in self.valid_files:
|
|
195
|
+
rels = get_dependents(self.archive, rels_path)
|
|
196
|
+
|
|
197
|
+
with self.archive.open(sheet_path, "r") as src:
|
|
198
|
+
xml = src.read()
|
|
199
|
+
node = fromstring(xml)
|
|
200
|
+
cs = Chartsheet.from_tree(node)
|
|
201
|
+
cs._parent = self.wb
|
|
202
|
+
cs.title = sheet.name
|
|
203
|
+
self.wb._add_sheet(cs)
|
|
204
|
+
|
|
205
|
+
drawings = rels.find(SpreadsheetDrawing._rel_type)
|
|
206
|
+
for rel in drawings:
|
|
207
|
+
charts, images = find_images(self.archive, rel.target)
|
|
208
|
+
for c in charts:
|
|
209
|
+
cs.add_chart(c)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def read_worksheets(self):
|
|
213
|
+
comment_warning = """Cell '{0}':{1} is part of a merged range but has a comment which will be removed because merged cells cannot contain any data."""
|
|
214
|
+
for sheet, rel in self.parser.find_sheets():
|
|
215
|
+
if rel.target not in self.valid_files:
|
|
216
|
+
continue
|
|
217
|
+
|
|
218
|
+
if "chartsheet" in rel.Type:
|
|
219
|
+
self.read_chartsheet(sheet, rel)
|
|
220
|
+
continue
|
|
221
|
+
|
|
222
|
+
rels_path = get_rels_path(rel.target)
|
|
223
|
+
rels = RelationshipList()
|
|
224
|
+
if rels_path in self.valid_files:
|
|
225
|
+
rels = get_dependents(self.archive, rels_path)
|
|
226
|
+
|
|
227
|
+
if self.read_only:
|
|
228
|
+
ws = ReadOnlyWorksheet(self.wb, sheet.name, rel.target, self.shared_strings)
|
|
229
|
+
ws.sheet_state = sheet.state
|
|
230
|
+
self.wb._sheets.append(ws)
|
|
231
|
+
continue
|
|
232
|
+
else:
|
|
233
|
+
fh = self.archive.open(rel.target)
|
|
234
|
+
ws = self.wb.create_sheet(sheet.name)
|
|
235
|
+
ws._rels = rels
|
|
236
|
+
ws_parser = WorksheetReader(ws, fh, self.shared_strings, self.data_only, self.rich_text)
|
|
237
|
+
ws_parser.bind_all()
|
|
238
|
+
fh.close()
|
|
239
|
+
|
|
240
|
+
# assign any comments to cells
|
|
241
|
+
for r in rels.find(COMMENTS_NS):
|
|
242
|
+
src = self.archive.read(r.target)
|
|
243
|
+
comment_sheet = CommentSheet.from_tree(fromstring(src))
|
|
244
|
+
for ref, comment in comment_sheet.comments:
|
|
245
|
+
try:
|
|
246
|
+
ws[ref].comment = comment
|
|
247
|
+
except AttributeError:
|
|
248
|
+
c = ws[ref]
|
|
249
|
+
if isinstance(c, MergedCell):
|
|
250
|
+
warnings.warn(comment_warning.format(ws.title, c.coordinate))
|
|
251
|
+
continue
|
|
252
|
+
|
|
253
|
+
# preserve link to VML file if VBA
|
|
254
|
+
if self.wb.vba_archive and ws.legacy_drawing:
|
|
255
|
+
ws.legacy_drawing = rels.get(ws.legacy_drawing).target
|
|
256
|
+
else:
|
|
257
|
+
ws.legacy_drawing = None
|
|
258
|
+
|
|
259
|
+
for t in ws_parser.tables:
|
|
260
|
+
src = self.archive.read(t)
|
|
261
|
+
xml = fromstring(src)
|
|
262
|
+
table = Table.from_tree(xml)
|
|
263
|
+
ws.add_table(table)
|
|
264
|
+
|
|
265
|
+
drawings = rels.find(SpreadsheetDrawing._rel_type)
|
|
266
|
+
for rel in drawings:
|
|
267
|
+
charts, images = find_images(self.archive, rel.target)
|
|
268
|
+
for c in charts:
|
|
269
|
+
ws.add_chart(c, c.anchor)
|
|
270
|
+
for im in images:
|
|
271
|
+
ws.add_image(im, im.anchor)
|
|
272
|
+
|
|
273
|
+
pivot_rel = rels.find(TableDefinition.rel_type)
|
|
274
|
+
pivot_caches = self.parser.pivot_caches
|
|
275
|
+
for r in pivot_rel:
|
|
276
|
+
pivot_path = r.Target
|
|
277
|
+
src = self.archive.read(pivot_path)
|
|
278
|
+
tree = fromstring(src)
|
|
279
|
+
pivot = TableDefinition.from_tree(tree)
|
|
280
|
+
pivot.cache = pivot_caches[pivot.cacheId]
|
|
281
|
+
ws.add_pivot(pivot)
|
|
282
|
+
|
|
283
|
+
ws.sheet_state = sheet.state
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def read(self):
|
|
287
|
+
action = "read manifest"
|
|
288
|
+
try:
|
|
289
|
+
self.read_manifest()
|
|
290
|
+
action = "read strings"
|
|
291
|
+
self.read_strings()
|
|
292
|
+
action = "read workbook"
|
|
293
|
+
self.read_workbook()
|
|
294
|
+
action = "read properties"
|
|
295
|
+
self.read_properties()
|
|
296
|
+
action = "read custom properties"
|
|
297
|
+
self.read_custom()
|
|
298
|
+
action = "read theme"
|
|
299
|
+
self.read_theme()
|
|
300
|
+
action = "read stylesheet"
|
|
301
|
+
apply_stylesheet(self.archive, self.wb)
|
|
302
|
+
action = "read worksheets"
|
|
303
|
+
self.read_worksheets()
|
|
304
|
+
action = "assign names"
|
|
305
|
+
self.parser.assign_names()
|
|
306
|
+
if not self.read_only:
|
|
307
|
+
self.archive.close()
|
|
308
|
+
except ValueError as e:
|
|
309
|
+
raise ValueError(
|
|
310
|
+
f"Unable to read workbook: could not {action} from {self.archive.filename}.\n"
|
|
311
|
+
"This is most probably because the workbook source files contain some invalid XML.\n"
|
|
312
|
+
"Please see the exception for more details."
|
|
313
|
+
) from e
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
|
|
317
|
+
data_only=False, keep_links=True, rich_text=False):
|
|
318
|
+
"""Open the given filename and return the workbook
|
|
319
|
+
|
|
320
|
+
:param filename: the path to open or a file-like object
|
|
321
|
+
:type filename: string or a file-like object open in binary mode c.f., :class:`zipfile.ZipFile`
|
|
322
|
+
|
|
323
|
+
:param read_only: optimised for reading, content cannot be edited
|
|
324
|
+
:type read_only: bool
|
|
325
|
+
|
|
326
|
+
:param keep_vba: preserve vba content (this does NOT mean you can use it)
|
|
327
|
+
:type keep_vba: bool
|
|
328
|
+
|
|
329
|
+
:param data_only: controls whether cells with formulae have either the formula (default) or the value stored the last time Excel read the sheet
|
|
330
|
+
:type data_only: bool
|
|
331
|
+
|
|
332
|
+
:param keep_links: whether links to external workbooks should be preserved. The default is True
|
|
333
|
+
:type keep_links: bool
|
|
334
|
+
|
|
335
|
+
:param rich_text: if set to True openpyxl will preserve any rich text formatting in cells. The default is False
|
|
336
|
+
:type rich_text: bool
|
|
337
|
+
|
|
338
|
+
:rtype: :class:`openpyxl.workbook.Workbook`
|
|
339
|
+
|
|
340
|
+
.. note::
|
|
341
|
+
|
|
342
|
+
When using lazy load, all worksheets will be :class:`openpyxl.worksheet.iter_worksheet.IterableWorksheet`
|
|
343
|
+
and the returned workbook will be read-only.
|
|
344
|
+
|
|
345
|
+
"""
|
|
346
|
+
reader = ExcelReader(filename, read_only, keep_vba,
|
|
347
|
+
data_only, keep_links, rich_text)
|
|
348
|
+
reader.read()
|
|
349
|
+
return reader.wb
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from openpyxl.cell.text import Text
|
|
4
|
+
|
|
5
|
+
from openpyxl.xml.functions import iterparse
|
|
6
|
+
from openpyxl.xml.constants import SHEET_MAIN_NS
|
|
7
|
+
from openpyxl.cell.rich_text import CellRichText
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def read_string_table(xml_source):
|
|
11
|
+
"""Read in all shared strings in the table"""
|
|
12
|
+
|
|
13
|
+
strings = []
|
|
14
|
+
STRING_TAG = '{%s}si' % SHEET_MAIN_NS
|
|
15
|
+
|
|
16
|
+
for _, node in iterparse(xml_source):
|
|
17
|
+
if node.tag == STRING_TAG:
|
|
18
|
+
text = Text.from_tree(node).content
|
|
19
|
+
text = text.replace('x005F_', '')
|
|
20
|
+
node.clear()
|
|
21
|
+
|
|
22
|
+
strings.append(text)
|
|
23
|
+
|
|
24
|
+
return strings
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def read_rich_text(xml_source):
|
|
28
|
+
"""Read in all shared strings in the table"""
|
|
29
|
+
|
|
30
|
+
strings = []
|
|
31
|
+
STRING_TAG = '{%s}si' % SHEET_MAIN_NS
|
|
32
|
+
|
|
33
|
+
for _, node in iterparse(xml_source):
|
|
34
|
+
if node.tag == STRING_TAG:
|
|
35
|
+
text = CellRichText.from_tree(node)
|
|
36
|
+
if len(text) == 0:
|
|
37
|
+
text = ''
|
|
38
|
+
elif len(text) == 1 and isinstance(text[0], str):
|
|
39
|
+
text = text[0]
|
|
40
|
+
node.clear()
|
|
41
|
+
|
|
42
|
+
strings.append(text)
|
|
43
|
+
|
|
44
|
+
return strings
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from warnings import warn
|
|
4
|
+
|
|
5
|
+
from openpyxl.xml.functions import fromstring
|
|
6
|
+
|
|
7
|
+
from openpyxl.packaging.relationship import (
|
|
8
|
+
get_dependents,
|
|
9
|
+
get_rels_path,
|
|
10
|
+
get_rel,
|
|
11
|
+
)
|
|
12
|
+
from openpyxl.packaging.workbook import WorkbookPackage
|
|
13
|
+
from openpyxl.workbook import Workbook
|
|
14
|
+
from openpyxl.workbook.defined_name import DefinedNameList
|
|
15
|
+
from openpyxl.workbook.external_link.external import read_external_link
|
|
16
|
+
from openpyxl.pivot.cache import CacheDefinition
|
|
17
|
+
from openpyxl.pivot.record import RecordList
|
|
18
|
+
from openpyxl.worksheet.print_settings import PrintTitles, PrintArea
|
|
19
|
+
|
|
20
|
+
from openpyxl.utils.datetime import CALENDAR_MAC_1904
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class WorkbookParser:
|
|
24
|
+
|
|
25
|
+
_rels = None
|
|
26
|
+
|
|
27
|
+
def __init__(self, archive, workbook_part_name, keep_links=True):
|
|
28
|
+
self.archive = archive
|
|
29
|
+
self.workbook_part_name = workbook_part_name
|
|
30
|
+
self.defined_names = DefinedNameList()
|
|
31
|
+
self.wb = Workbook()
|
|
32
|
+
self.keep_links = keep_links
|
|
33
|
+
self.sheets = []
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def rels(self):
|
|
38
|
+
if self._rels is None:
|
|
39
|
+
self._rels = get_dependents(self.archive, get_rels_path(self.workbook_part_name)).to_dict()
|
|
40
|
+
return self._rels
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def parse(self):
|
|
44
|
+
src = self.archive.read(self.workbook_part_name)
|
|
45
|
+
node = fromstring(src)
|
|
46
|
+
package = WorkbookPackage.from_tree(node)
|
|
47
|
+
if package.properties.date1904:
|
|
48
|
+
self.wb.epoch = CALENDAR_MAC_1904
|
|
49
|
+
|
|
50
|
+
self.wb.code_name = package.properties.codeName
|
|
51
|
+
self.wb.active = package.active
|
|
52
|
+
self.wb.views = package.bookViews
|
|
53
|
+
self.sheets = package.sheets
|
|
54
|
+
self.wb.calculation = package.calcPr
|
|
55
|
+
self.caches = package.pivotCaches
|
|
56
|
+
|
|
57
|
+
# external links contain cached worksheets and can be very big
|
|
58
|
+
if not self.keep_links:
|
|
59
|
+
package.externalReferences = []
|
|
60
|
+
|
|
61
|
+
for ext_ref in package.externalReferences:
|
|
62
|
+
rel = self.rels.get(ext_ref.id)
|
|
63
|
+
self.wb._external_links.append(
|
|
64
|
+
read_external_link(self.archive, rel.Target)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
if package.definedNames:
|
|
68
|
+
self.defined_names = package.definedNames
|
|
69
|
+
|
|
70
|
+
self.wb.security = package.workbookProtection
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def find_sheets(self):
|
|
74
|
+
"""
|
|
75
|
+
Find all sheets in the workbook and return the link to the source file.
|
|
76
|
+
|
|
77
|
+
Older XLSM files sometimes contain invalid sheet elements.
|
|
78
|
+
Warn user when these are removed.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
for sheet in self.sheets:
|
|
82
|
+
if not sheet.id:
|
|
83
|
+
msg = f"File contains an invalid specification for {0}. This will be removed".format(sheet.name)
|
|
84
|
+
warn(msg)
|
|
85
|
+
continue
|
|
86
|
+
yield sheet, self.rels[sheet.id]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def assign_names(self):
|
|
90
|
+
"""
|
|
91
|
+
Bind defined names and other definitions to worksheets or the workbook
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
for idx, names in self.defined_names.by_sheet().items():
|
|
95
|
+
if idx == "global":
|
|
96
|
+
self.wb.defined_names = names
|
|
97
|
+
continue
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
sheet = self.wb._sheets[idx]
|
|
101
|
+
except IndexError:
|
|
102
|
+
warn(f"Defined names for sheet index {idx} cannot be located")
|
|
103
|
+
continue
|
|
104
|
+
|
|
105
|
+
for name, defn in names.items():
|
|
106
|
+
reserved = defn.is_reserved
|
|
107
|
+
if reserved is None:
|
|
108
|
+
sheet.defined_names[name] = defn
|
|
109
|
+
|
|
110
|
+
elif reserved == "Print_Titles":
|
|
111
|
+
titles = PrintTitles.from_string(defn.value)
|
|
112
|
+
sheet._print_rows = titles.rows
|
|
113
|
+
sheet._print_cols = titles.cols
|
|
114
|
+
elif reserved == "Print_Area":
|
|
115
|
+
try:
|
|
116
|
+
sheet._print_area = PrintArea.from_string(defn.value)
|
|
117
|
+
except TypeError:
|
|
118
|
+
warn(f"Print area cannot be set to Defined name: {defn.value}.")
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def pivot_caches(self):
|
|
123
|
+
"""
|
|
124
|
+
Get PivotCache objects
|
|
125
|
+
"""
|
|
126
|
+
d = {}
|
|
127
|
+
for c in self.caches:
|
|
128
|
+
cache = get_rel(self.archive, self.rels, id=c.id, cls=CacheDefinition)
|
|
129
|
+
if cache.deps:
|
|
130
|
+
records = get_rel(self.archive, cache.deps, cache.id, RecordList)
|
|
131
|
+
cache.records = records
|
|
132
|
+
d[c.cacheId] = cache
|
|
133
|
+
return d
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from .alignment import Alignment
|
|
5
|
+
from .borders import Border, Side
|
|
6
|
+
from .colors import Color
|
|
7
|
+
from .fills import PatternFill, GradientFill, Fill
|
|
8
|
+
from .fonts import Font, DEFAULT_FONT
|
|
9
|
+
from .numbers import NumberFormatDescriptor, is_date_format, is_builtin
|
|
10
|
+
from .protection import Protection
|
|
11
|
+
from .named_styles import NamedStyle
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from openpyxl.compat import safe_string
|
|
4
|
+
|
|
5
|
+
from openpyxl.descriptors import Bool, MinMax, Min, Alias, NoneSet
|
|
6
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
horizontal_alignments = (
|
|
10
|
+
"general", "left", "center", "right", "fill", "justify", "centerContinuous",
|
|
11
|
+
"distributed", )
|
|
12
|
+
vertical_aligments = (
|
|
13
|
+
"top", "center", "bottom", "justify", "distributed",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
class Alignment(Serialisable):
|
|
17
|
+
"""Alignment options for use in styles."""
|
|
18
|
+
|
|
19
|
+
tagname = "alignment"
|
|
20
|
+
|
|
21
|
+
horizontal = NoneSet(values=horizontal_alignments)
|
|
22
|
+
vertical = NoneSet(values=vertical_aligments)
|
|
23
|
+
textRotation = NoneSet(values=range(181))
|
|
24
|
+
textRotation.values.add(255)
|
|
25
|
+
text_rotation = Alias('textRotation')
|
|
26
|
+
wrapText = Bool(allow_none=True)
|
|
27
|
+
wrap_text = Alias('wrapText')
|
|
28
|
+
shrinkToFit = Bool(allow_none=True)
|
|
29
|
+
shrink_to_fit = Alias('shrinkToFit')
|
|
30
|
+
indent = MinMax(min=0, max=255)
|
|
31
|
+
relativeIndent = MinMax(min=-255, max=255)
|
|
32
|
+
justifyLastLine = Bool(allow_none=True)
|
|
33
|
+
readingOrder = Min(min=0)
|
|
34
|
+
|
|
35
|
+
def __init__(self, horizontal=None, vertical=None,
|
|
36
|
+
textRotation=0, wrapText=None, shrinkToFit=None, indent=0, relativeIndent=0,
|
|
37
|
+
justifyLastLine=None, readingOrder=0, text_rotation=None,
|
|
38
|
+
wrap_text=None, shrink_to_fit=None, mergeCell=None):
|
|
39
|
+
self.horizontal = horizontal
|
|
40
|
+
self.vertical = vertical
|
|
41
|
+
self.indent = indent
|
|
42
|
+
self.relativeIndent = relativeIndent
|
|
43
|
+
self.justifyLastLine = justifyLastLine
|
|
44
|
+
self.readingOrder = readingOrder
|
|
45
|
+
if text_rotation is not None:
|
|
46
|
+
textRotation = text_rotation
|
|
47
|
+
if textRotation is not None:
|
|
48
|
+
self.textRotation = int(textRotation)
|
|
49
|
+
if wrap_text is not None:
|
|
50
|
+
wrapText = wrap_text
|
|
51
|
+
self.wrapText = wrapText
|
|
52
|
+
if shrink_to_fit is not None:
|
|
53
|
+
shrinkToFit = shrink_to_fit
|
|
54
|
+
self.shrinkToFit = shrinkToFit
|
|
55
|
+
# mergeCell is vestigial
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def __iter__(self):
|
|
59
|
+
for attr in self.__attrs__:
|
|
60
|
+
value = getattr(self, attr)
|
|
61
|
+
if value is not None and value != 0:
|
|
62
|
+
yield attr, safe_string(value)
|