XlsxWriter 3.3.1__tar.gz → 3.3.3__tar.gz
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.
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/Changes +53 -0
- {xlsxwriter-3.3.1/xlsxwriter.egg-info → xlsxwriter-3.3.3}/PKG-INFO +3 -1
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/README.rst +2 -0
- xlsxwriter-3.3.3/examples/pivot_table.py +287 -0
- xlsxwriter-3.3.3/examples/theme_custom.py +36 -0
- xlsxwriter-3.3.3/examples/theme_excel_2023.py +20 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/pyproject.toml +1 -1
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/__init__.py +1 -1
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/contenttypes.py +19 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/core.py +7 -6
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/exceptions.py +4 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/format.py +1 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/packager.py +59 -0
- xlsxwriter-3.3.3/xlsxwriter/pivot_cache.py +165 -0
- xlsxwriter-3.3.3/xlsxwriter/pivot_table.py +809 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/utility.py +9 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/workbook.py +161 -37
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/worksheet.py +396 -223
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3/xlsxwriter.egg-info}/PKG-INFO +3 -1
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter.egg-info/SOURCES.txt +5 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/LICENSE.txt +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/MANIFEST.in +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/array_formula.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/autofilter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/autofilter_data.txt +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/autofit.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/autofit_manually.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/background.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/cell_indentation.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_area.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_bar.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_clustered.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_column.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_combined.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_data_labels.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_data_table.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_data_tools.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_date_axis.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_doughnut.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_gauge.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_gradient.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_line.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_pareto.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_pattern.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_pie.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_radar.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_scatter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_secondary_axis.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_stock.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chart_styles.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/chartsheet.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/check_close.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/checkbox.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/colors.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/comments1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/comments2.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/conditional_format.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/context_manager.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/data_validate.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/datetimes.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/defined_name.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/demo.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/diagonal_border.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/django_simple.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/doc_properties.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/dynamic_arrays.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/embedded_images.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/headers_footers.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/hello_world.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/hide_row_col.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/hide_sheet.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/http_server.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/hyperlink.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/ignore_errors.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/images.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/images_bytesio.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/inheritance1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/inheritance2.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/lambda.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/macros.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/merge1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/merge_rich_string.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/outline.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/outline_collapsed.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_autofilter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_chart.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_chart_columns.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_chart_line.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_column_formats.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_conditional_format.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_datetime.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_header_format.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_multiple.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_percentage.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_positioning.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_simple.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/pandas_table.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/panes.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_chart.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_checkbox.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_conditional_format.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_format_custom.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_format_default.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_multiple.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_positioning.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_simple.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_sparklines.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/polars_xlsxwriter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/rich_strings.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/right_to_left.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/sensitivity_label.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/sparklines1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/sparklines2.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/tab_colors.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/tables.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/text_indent.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/textbox.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/tutorial1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/tutorial2.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/tutorial3.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/unicode.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/unicode_polish_utf8.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/unicode_polish_utf8.txt +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/unicode_shift_jis.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/unicode_shift_jis.txt +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/user_types1.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/user_types2.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/user_types3.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/vbaProject.bin +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/vba_extract.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/watermark.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/examples/worksheet_protection.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/setup.cfg +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/app.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_area.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_bar.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_column.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_doughnut.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_line.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_pie.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_radar.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_scatter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_stock.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chart_title.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/chartsheet.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/color.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/comments.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/custom.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/drawing.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/feature_property_bag.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/image.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/metadata.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/relationships.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/rich_value.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/rich_value_rel.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/rich_value_structure.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/rich_value_types.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/shape.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/sharedstrings.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/styles.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/table.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/theme.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/url.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/vml.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter/xmlwriter.py +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter.egg-info/dependency_links.txt +0 -0
- {xlsxwriter-3.3.1 → xlsxwriter-3.3.3}/xlsxwriter.egg-info/top_level.txt +0 -0
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
|
|
2
|
+
Release 3.3.3 - November 20 2026
|
|
3
|
+
--------------------------------
|
|
4
|
+
|
|
5
|
+
* Added support for worksheet pivot tables via the :func:`add_pivot_table`
|
|
6
|
+
method. Pivot tables can have row, column, filter and value fields, and the
|
|
7
|
+
value fields can have different functions, custom names and number formats.
|
|
8
|
+
The pivot table style, layout and grand totals can also be set. See
|
|
9
|
+
:ref:`pivot_tables` and :ref:`ex_pivot_table`.
|
|
10
|
+
|
|
11
|
+
**Note**, the pivot table data isn't stored in the file. Excel builds the
|
|
12
|
+
pivot table from the source data when the file is opened. As a result,
|
|
13
|
+
applications that don't refresh pivot tables on load will show an empty
|
|
14
|
+
pivot table, and Excel will ask to save the file on close even if no
|
|
15
|
+
changes were made. See :ref:`pivot_table_limitations` for details.
|
|
16
|
+
|
|
17
|
+
:feature:`1231`.
|
|
18
|
+
|
|
19
|
+
Release 3.3.2 - November 19 2026
|
|
20
|
+
--------------------------------
|
|
21
|
+
|
|
22
|
+
* Added documentation and examples for the ``excel_2023_theme``,
|
|
23
|
+
``default_format_properties``, ``default_row_height`` and
|
|
24
|
+
``default_column_width`` Workbook options. See :ref:`ex_theme_excel_2023`
|
|
25
|
+
and :ref:`ex_theme_custom`.
|
|
26
|
+
|
|
27
|
+
:feature:`1163`.
|
|
28
|
+
|
|
29
|
+
* Fixed issue where a ``created`` date in :func:`set_properties` was replaced
|
|
30
|
+
with the current time if it was a ``datetime.date``. Also allow a
|
|
31
|
+
``datetime.date`` in :func:`set_custom_property`.
|
|
32
|
+
|
|
33
|
+
:issue:`1225`.
|
|
34
|
+
|
|
35
|
+
* Fixed issue where timezone aware datetimes in :func:`set_properties` and
|
|
36
|
+
:func:`set_custom_property` weren't converted to UTC.
|
|
37
|
+
|
|
38
|
+
:issue:`1227`.
|
|
39
|
+
|
|
40
|
+
* Fixed issue where a rejected :func:`add_table`, :func:`merge_range` or
|
|
41
|
+
:func:`autofilter` could leave reserved cells that caused a later
|
|
42
|
+
``OverlappingRange`` exception.
|
|
43
|
+
|
|
44
|
+
:issue:`1229`.
|
|
45
|
+
|
|
46
|
+
* Improved the performance of :func:`write_formula` and other methods that
|
|
47
|
+
handle formulas.
|
|
48
|
+
|
|
49
|
+
:issue:`1228`.
|
|
50
|
+
|
|
51
|
+
* Fixed issue where function names in formula string literals, and names such
|
|
52
|
+
as ``MYSINGLE()``, were treated as "future" functions.
|
|
53
|
+
|
|
54
|
+
|
|
2
55
|
Release 3.3.1 - October 28 2026
|
|
3
56
|
-------------------------------
|
|
4
57
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xlsxwriter
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.3
|
|
4
4
|
Summary: A Python module for creating Excel XLSX files.
|
|
5
5
|
Author-email: John McNamara <jmcnamara@cpan.org>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -43,6 +43,8 @@ including:
|
|
|
43
43
|
* Autofilters.
|
|
44
44
|
* Data validation and drop down lists.
|
|
45
45
|
* Conditional formatting.
|
|
46
|
+
* Worksheet tables.
|
|
47
|
+
* Pivot tables.
|
|
46
48
|
* Worksheet PNG/JPEG/GIF/BMP/WMF/EMF images.
|
|
47
49
|
* Rich multi-format strings.
|
|
48
50
|
* Cell comments.
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# An example of how to create pivot tables with the XlsxWriter module.
|
|
4
|
+
#
|
|
5
|
+
# A pivot table is a way of grouping and summarizing the data in a worksheet
|
|
6
|
+
# range.
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
9
|
+
#
|
|
10
|
+
# Copyright (c) 2013-2026, John McNamara, jmcnamara@cpan.org
|
|
11
|
+
#
|
|
12
|
+
import xlsxwriter
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
workbook = xlsxwriter.Workbook("pivot_table.xlsx")
|
|
17
|
+
|
|
18
|
+
# Add a worksheet with some sample data for the pivot tables.
|
|
19
|
+
worksheet = workbook.add_worksheet("Data")
|
|
20
|
+
populate_pivot_data(workbook, worksheet)
|
|
21
|
+
|
|
22
|
+
# -------------------------------------------------------------------------
|
|
23
|
+
# 1. Add an empty pivot table.
|
|
24
|
+
# -------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
# Add a pivot table based on the worksheet data to a new worksheet.
|
|
27
|
+
worksheet = workbook.add_worksheet("Pivot1")
|
|
28
|
+
worksheet.add_pivot_table("A3", {"source": "Data!A1:D51"})
|
|
29
|
+
|
|
30
|
+
# -------------------------------------------------------------------------
|
|
31
|
+
# 2. Add a pivot table with a Row field and a Value field.
|
|
32
|
+
# -------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
# Add a pivot table that summarizes the "Volume" data by "Region". Note
|
|
35
|
+
# that the data source can also be specified as a list.
|
|
36
|
+
worksheet = workbook.add_worksheet("Pivot2")
|
|
37
|
+
worksheet.add_pivot_table(
|
|
38
|
+
2,
|
|
39
|
+
0,
|
|
40
|
+
{
|
|
41
|
+
"source": ["Data", 0, 0, 50, 3],
|
|
42
|
+
"rows": ["Region"],
|
|
43
|
+
"values": [{"field": "Volume"}],
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# -------------------------------------------------------------------------
|
|
48
|
+
# 3. Add a pivot table with a Row field, a Column field and a Value field.
|
|
49
|
+
# -------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
# Add a pivot table that summarizes the "Volume" data by "Region" and
|
|
52
|
+
# "Item".
|
|
53
|
+
worksheet = workbook.add_worksheet("Pivot3")
|
|
54
|
+
worksheet.add_pivot_table(
|
|
55
|
+
"A3",
|
|
56
|
+
{
|
|
57
|
+
"source": "Data!A1:D51",
|
|
58
|
+
"rows": ["Region"],
|
|
59
|
+
"columns": ["Item"],
|
|
60
|
+
"values": [{"field": "Volume"}],
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# -------------------------------------------------------------------------
|
|
65
|
+
# 4. Add a pivot table with a Filter field.
|
|
66
|
+
# -------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
# Add a pivot table that summarizes the "Volume" data by "Region", with a
|
|
69
|
+
# filter on "Month". The filter is displayed in the first row and the
|
|
70
|
+
# pivot table body starts in the third row.
|
|
71
|
+
worksheet = workbook.add_worksheet("Pivot4")
|
|
72
|
+
worksheet.add_pivot_table(
|
|
73
|
+
"A1",
|
|
74
|
+
{
|
|
75
|
+
"source": "Data!A1:D51",
|
|
76
|
+
"rows": ["Region"],
|
|
77
|
+
"values": [{"field": "Volume"}],
|
|
78
|
+
"filters": ["Month"],
|
|
79
|
+
},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# -------------------------------------------------------------------------
|
|
83
|
+
# 5. Add a pivot table with two Row fields.
|
|
84
|
+
# -------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
# Add a pivot table that summarizes the "Volume" data by "Region" and then
|
|
87
|
+
# by "Item" within each region.
|
|
88
|
+
worksheet = workbook.add_worksheet("Pivot5")
|
|
89
|
+
worksheet.add_pivot_table(
|
|
90
|
+
"A3",
|
|
91
|
+
{
|
|
92
|
+
"source": "Data!A1:D51",
|
|
93
|
+
"rows": ["Region", "Item"],
|
|
94
|
+
"values": [{"field": "Volume"}],
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# -------------------------------------------------------------------------
|
|
99
|
+
# 6. Add a pivot table with several Value fields.
|
|
100
|
+
# -------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
# Add a pivot table that summarizes the "Volume" data by "Region" using
|
|
103
|
+
# different functions.
|
|
104
|
+
worksheet = workbook.add_worksheet("Pivot6")
|
|
105
|
+
worksheet.add_pivot_table(
|
|
106
|
+
"A3",
|
|
107
|
+
{
|
|
108
|
+
"source": "Data!A1:D51",
|
|
109
|
+
"rows": ["Region"],
|
|
110
|
+
"values": [
|
|
111
|
+
{"field": "Volume"},
|
|
112
|
+
{"field": "Volume", "function": "count"},
|
|
113
|
+
{"field": "Volume", "function": "average"},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# -------------------------------------------------------------------------
|
|
119
|
+
# 7. Add a pivot table with a custom name and number format.
|
|
120
|
+
# -------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
# Add a pivot table that summarizes the "Volume" data by "Region", with a
|
|
123
|
+
# custom name and number format.
|
|
124
|
+
worksheet = workbook.add_worksheet("Pivot7")
|
|
125
|
+
worksheet.add_pivot_table(
|
|
126
|
+
"A3",
|
|
127
|
+
{
|
|
128
|
+
"source": "Data!A1:D51",
|
|
129
|
+
"rows": ["Region"],
|
|
130
|
+
"values": [
|
|
131
|
+
{"field": "Volume", "name": "Total Volume", "num_format": "#,##0"},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# -------------------------------------------------------------------------
|
|
137
|
+
# 8. Add a pivot table with a different style and no grand totals.
|
|
138
|
+
# -------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
# Add a pivot table that summarizes the "Volume" data by "Region" and
|
|
141
|
+
# "Item", without grand totals.
|
|
142
|
+
worksheet = workbook.add_worksheet("Pivot8")
|
|
143
|
+
worksheet.add_pivot_table(
|
|
144
|
+
"A3",
|
|
145
|
+
{
|
|
146
|
+
"source": "Data!A1:D51",
|
|
147
|
+
"rows": ["Region"],
|
|
148
|
+
"columns": ["Item"],
|
|
149
|
+
"values": [{"field": "Volume"}],
|
|
150
|
+
"style": "Pivot Style Medium 9",
|
|
151
|
+
"row_grand_totals": False,
|
|
152
|
+
"column_grand_totals": False,
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# -------------------------------------------------------------------------
|
|
157
|
+
# 9. Add a pivot table with a tabular layout.
|
|
158
|
+
# -------------------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
# Add a pivot table that summarizes the "Volume" data by "Region" and
|
|
161
|
+
# "Item", with each row field in its own column.
|
|
162
|
+
worksheet = workbook.add_worksheet("Pivot9")
|
|
163
|
+
worksheet.add_pivot_table(
|
|
164
|
+
"A3",
|
|
165
|
+
{
|
|
166
|
+
"source": "Data!A1:D51",
|
|
167
|
+
"rows": ["Region", "Item"],
|
|
168
|
+
"values": [{"field": "Volume"}],
|
|
169
|
+
"layout": "tabular",
|
|
170
|
+
},
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# -------------------------------------------------------------------------
|
|
174
|
+
# 10. Add two pivot tables to the same worksheet.
|
|
175
|
+
# -------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
# Add two pivot tables side by side that summarize the "Volume" data by
|
|
178
|
+
# "Region" in one and by "Item" in the other.
|
|
179
|
+
worksheet = workbook.add_worksheet("Pivot10")
|
|
180
|
+
worksheet.add_pivot_table(
|
|
181
|
+
"A3",
|
|
182
|
+
{
|
|
183
|
+
"source": "Data!A1:D51",
|
|
184
|
+
"rows": ["Region"],
|
|
185
|
+
"values": [{"field": "Volume"}],
|
|
186
|
+
},
|
|
187
|
+
)
|
|
188
|
+
worksheet.add_pivot_table(
|
|
189
|
+
"F3",
|
|
190
|
+
{
|
|
191
|
+
"source": "Data!A1:D51",
|
|
192
|
+
"rows": ["Item"],
|
|
193
|
+
"values": [{"field": "Volume"}],
|
|
194
|
+
},
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
# -------------------------------------------------------------------------
|
|
198
|
+
# 11. Add a pivot table to the same worksheet as the data.
|
|
199
|
+
# -------------------------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
# Add a new worksheet with a copy of the sample data.
|
|
202
|
+
worksheet = workbook.add_worksheet("Pivot11")
|
|
203
|
+
populate_pivot_data(workbook, worksheet)
|
|
204
|
+
|
|
205
|
+
# Add a pivot table to the right of the data that summarizes the "Volume"
|
|
206
|
+
# data by "Region".
|
|
207
|
+
worksheet.add_pivot_table(
|
|
208
|
+
"G3",
|
|
209
|
+
{
|
|
210
|
+
"source": "Pivot11!A1:D51",
|
|
211
|
+
"rows": ["Region"],
|
|
212
|
+
"values": [{"field": "Volume"}],
|
|
213
|
+
},
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
workbook.close()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def populate_pivot_data(workbook, worksheet):
|
|
220
|
+
# Add the sample data for the pivot tables to the worksheet.
|
|
221
|
+
data = [
|
|
222
|
+
["East", "Apple", 9000, "July"],
|
|
223
|
+
["East", "Apple", 5000, "April"],
|
|
224
|
+
["South", "Orange", 9000, "September"],
|
|
225
|
+
["North", "Apple", 2000, "November"],
|
|
226
|
+
["West", "Apple", 9000, "November"],
|
|
227
|
+
["South", "Pear", 7000, "October"],
|
|
228
|
+
["North", "Pear", 9000, "August"],
|
|
229
|
+
["West", "Orange", 1000, "December"],
|
|
230
|
+
["West", "Grape", 1000, "November"],
|
|
231
|
+
["South", "Pear", 10000, "April"],
|
|
232
|
+
["West", "Grape", 6000, "January"],
|
|
233
|
+
["South", "Orange", 3000, "May"],
|
|
234
|
+
["North", "Apple", 3000, "December"],
|
|
235
|
+
["South", "Apple", 7000, "February"],
|
|
236
|
+
["West", "Grape", 1000, "December"],
|
|
237
|
+
["East", "Grape", 8000, "February"],
|
|
238
|
+
["South", "Grape", 10000, "June"],
|
|
239
|
+
["West", "Pear", 7000, "December"],
|
|
240
|
+
["South", "Apple", 2000, "October"],
|
|
241
|
+
["East", "Grape", 7000, "December"],
|
|
242
|
+
["North", "Grape", 6000, "July"],
|
|
243
|
+
["East", "Pear", 8000, "February"],
|
|
244
|
+
["North", "Apple", 7000, "August"],
|
|
245
|
+
["North", "Orange", 7000, "July"],
|
|
246
|
+
["North", "Apple", 6000, "June"],
|
|
247
|
+
["South", "Grape", 8000, "September"],
|
|
248
|
+
["West", "Apple", 3000, "October"],
|
|
249
|
+
["South", "Orange", 10000, "November"],
|
|
250
|
+
["West", "Grape", 4000, "December"],
|
|
251
|
+
["North", "Orange", 5000, "August"],
|
|
252
|
+
["East", "Orange", 1000, "November"],
|
|
253
|
+
["East", "Orange", 4000, "October"],
|
|
254
|
+
["North", "Grape", 5000, "August"],
|
|
255
|
+
["East", "Apple", 1000, "July"],
|
|
256
|
+
["South", "Apple", 10000, "March"],
|
|
257
|
+
["East", "Grape", 7000, "October"],
|
|
258
|
+
["West", "Grape", 1000, "September"],
|
|
259
|
+
["East", "Grape", 10000, "October"],
|
|
260
|
+
["South", "Orange", 8000, "March"],
|
|
261
|
+
["North", "Apple", 4000, "July"],
|
|
262
|
+
["South", "Orange", 5000, "July"],
|
|
263
|
+
["West", "Apple", 4000, "June"],
|
|
264
|
+
["East", "Apple", 5000, "April"],
|
|
265
|
+
["North", "Pear", 3000, "August"],
|
|
266
|
+
["East", "Grape", 9000, "November"],
|
|
267
|
+
["North", "Orange", 8000, "October"],
|
|
268
|
+
["East", "Apple", 10000, "June"],
|
|
269
|
+
["South", "Pear", 1000, "December"],
|
|
270
|
+
["North", "Grape", 10000, "July"],
|
|
271
|
+
["East", "Grape", 6000, "February"],
|
|
272
|
+
]
|
|
273
|
+
|
|
274
|
+
# Widen the columns for clarity.
|
|
275
|
+
worksheet.set_column(0, 3, 12)
|
|
276
|
+
|
|
277
|
+
# Write the header titles.
|
|
278
|
+
header_format = workbook.add_format({"bold": True})
|
|
279
|
+
worksheet.write_row(0, 0, ["Region", "Item", "Volume", "Month"], header_format)
|
|
280
|
+
|
|
281
|
+
# Write the other worksheet data.
|
|
282
|
+
for row, row_data in enumerate(data, 1):
|
|
283
|
+
worksheet.write_row(row, 0, row_data)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
if __name__ == "__main__":
|
|
287
|
+
main()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# An example of changing the default theme for a workbook to a user supplied
|
|
4
|
+
# custom theme using XlsxWriter.
|
|
5
|
+
#
|
|
6
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
7
|
+
#
|
|
8
|
+
# Copyright (c) 2013-2026, John McNamara, jmcnamara@cpan.org
|
|
9
|
+
#
|
|
10
|
+
import xlsxwriter
|
|
11
|
+
|
|
12
|
+
# Set the default format to match the custom theme. Note, the font scheme is set
|
|
13
|
+
# to "minor" to indicate that the font is part of the theme.
|
|
14
|
+
workbook = xlsxwriter.Workbook(
|
|
15
|
+
"theme_custom.xlsx",
|
|
16
|
+
{
|
|
17
|
+
"default_format_properties": {
|
|
18
|
+
"font_name": "Arial",
|
|
19
|
+
"font_size": 11,
|
|
20
|
+
"font_scheme": "minor",
|
|
21
|
+
},
|
|
22
|
+
"default_row_height": 19,
|
|
23
|
+
"default_column_width": 72,
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Add a custom theme to the workbook. This can be a .thmx file, an .xlsx file,
|
|
28
|
+
# or a theme1.xml file extracted from an unzipped xlsx file.
|
|
29
|
+
workbook.use_custom_theme("Technic.thmx")
|
|
30
|
+
|
|
31
|
+
worksheet = workbook.add_worksheet()
|
|
32
|
+
|
|
33
|
+
# Write some text to demonstrate the changed theme.
|
|
34
|
+
worksheet.write("A1", "Hello")
|
|
35
|
+
|
|
36
|
+
workbook.close()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# An example of changing the default theme for a workbook to the Excel 2023
|
|
4
|
+
# Office/Aptos theme using XlsxWriter.
|
|
5
|
+
#
|
|
6
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
7
|
+
#
|
|
8
|
+
# Copyright (c) 2013-2026, John McNamara, jmcnamara@cpan.org
|
|
9
|
+
#
|
|
10
|
+
import xlsxwriter
|
|
11
|
+
|
|
12
|
+
# Use the Excel 2023 Office/Aptos theme in the workbook.
|
|
13
|
+
workbook = xlsxwriter.Workbook("theme_excel_2023.xlsx", {"excel_2023_theme": True})
|
|
14
|
+
|
|
15
|
+
worksheet = workbook.add_worksheet()
|
|
16
|
+
|
|
17
|
+
# Write some text to demonstrate the changed theme.
|
|
18
|
+
worksheet.write("A1", "Hello")
|
|
19
|
+
|
|
20
|
+
workbook.close()
|
|
@@ -150,6 +150,25 @@ class ContentTypes(xmlwriter.XMLwriter):
|
|
|
150
150
|
|
|
151
151
|
self._add_override((table_name, APP_DOCUMENT + "spreadsheetml.table+xml"))
|
|
152
152
|
|
|
153
|
+
def _add_pivot_table_name(self, pivot_table_name: str) -> None:
|
|
154
|
+
# Add the name of a pivot table to the ContentTypes overrides.
|
|
155
|
+
pivot_table_name = "/xl/pivotTables/" + pivot_table_name + ".xml"
|
|
156
|
+
|
|
157
|
+
self._add_override(
|
|
158
|
+
(pivot_table_name, APP_DOCUMENT + "spreadsheetml.pivotTable+xml")
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
def _add_pivot_cache_name(self, pivot_cache_name: str) -> None:
|
|
162
|
+
# Add the name of a pivot cache to the ContentTypes overrides.
|
|
163
|
+
pivot_cache_name = "/xl/pivotCache/" + pivot_cache_name + ".xml"
|
|
164
|
+
|
|
165
|
+
self._add_override(
|
|
166
|
+
(
|
|
167
|
+
pivot_cache_name,
|
|
168
|
+
APP_DOCUMENT + "spreadsheetml.pivotCacheDefinition+xml",
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
|
|
153
172
|
def _add_vba_project(self) -> None:
|
|
154
173
|
# Add a vbaProject to the ContentTypes defaults.
|
|
155
174
|
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
# Copyright (c) 2013-2026, John McNamara, jmcnamara@cpan.org
|
|
8
8
|
#
|
|
9
9
|
|
|
10
|
-
from datetime import datetime, timezone
|
|
10
|
+
from datetime import date, datetime, timezone
|
|
11
11
|
from typing import Dict, Union
|
|
12
12
|
|
|
13
13
|
from xlsxwriter import xmlwriter
|
|
14
|
+
from xlsxwriter.utility import _datetime_to_w3cdtf
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class Core(xmlwriter.XMLwriter):
|
|
@@ -47,11 +48,11 @@ class Core(xmlwriter.XMLwriter):
|
|
|
47
48
|
# Assemble and write the XML file.
|
|
48
49
|
|
|
49
50
|
# Set the creation date for the file.
|
|
50
|
-
|
|
51
|
-
if not isinstance(
|
|
52
|
-
|
|
51
|
+
created = self.properties.get("created")
|
|
52
|
+
if not isinstance(created, date):
|
|
53
|
+
created = datetime.now(timezone.utc)
|
|
53
54
|
|
|
54
|
-
self.iso_date =
|
|
55
|
+
self.iso_date = _datetime_to_w3cdtf(created)
|
|
55
56
|
|
|
56
57
|
# Write the XML declaration.
|
|
57
58
|
self._xml_declaration()
|
|
@@ -73,7 +74,7 @@ class Core(xmlwriter.XMLwriter):
|
|
|
73
74
|
# Close the file.
|
|
74
75
|
self._xml_close()
|
|
75
76
|
|
|
76
|
-
def _set_properties(self, properties: Dict[str, Union[str,
|
|
77
|
+
def _set_properties(self, properties: Dict[str, Union[str, date]]) -> None:
|
|
77
78
|
# Set the document properties.
|
|
78
79
|
self.properties = properties
|
|
79
80
|
|
|
@@ -40,6 +40,10 @@ class OverlappingRange(XlsxInputError):
|
|
|
40
40
|
"""Worksheet merge range or table overlaps previous range."""
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
class PivotTableError(XlsxInputError):
|
|
44
|
+
"""Pivot table options or source data are invalid."""
|
|
45
|
+
|
|
46
|
+
|
|
43
47
|
class UndefinedImageSize(XlsxFileError):
|
|
44
48
|
"""No size data found in image file."""
|
|
45
49
|
|
|
@@ -23,6 +23,7 @@ from xlsxwriter.custom import Custom
|
|
|
23
23
|
from xlsxwriter.exceptions import EmptyChartSeries
|
|
24
24
|
from xlsxwriter.feature_property_bag import FeaturePropertyBag
|
|
25
25
|
from xlsxwriter.metadata import Metadata
|
|
26
|
+
from xlsxwriter.pivot_table import PivotTable
|
|
26
27
|
from xlsxwriter.relationships import Relationships
|
|
27
28
|
from xlsxwriter.rich_value import RichValue
|
|
28
29
|
from xlsxwriter.rich_value_rel import RichValueRel
|
|
@@ -99,6 +100,8 @@ class Packager:
|
|
|
99
100
|
self.chart_count = 0
|
|
100
101
|
self.drawing_count = 0
|
|
101
102
|
self.table_count = 0
|
|
103
|
+
self.pivot_table_count = 0
|
|
104
|
+
self.pivot_cache_count = 0
|
|
102
105
|
self.num_vml_files = 0
|
|
103
106
|
self.num_comment_files = 0
|
|
104
107
|
self.named_ranges = []
|
|
@@ -126,6 +129,7 @@ class Packager:
|
|
|
126
129
|
self.num_vml_files = workbook.num_vml_files
|
|
127
130
|
self.num_comment_files = workbook.num_comment_files
|
|
128
131
|
self.named_ranges = workbook.named_ranges
|
|
132
|
+
self.pivot_cache_count = len(workbook.pivot_caches)
|
|
129
133
|
|
|
130
134
|
for worksheet in self.workbook.worksheets():
|
|
131
135
|
if worksheet.is_chartsheet:
|
|
@@ -133,6 +137,8 @@ class Packager:
|
|
|
133
137
|
else:
|
|
134
138
|
self.worksheet_count += 1
|
|
135
139
|
|
|
140
|
+
self.pivot_table_count += len(worksheet.pivot_tables)
|
|
141
|
+
|
|
136
142
|
def _create_package(self):
|
|
137
143
|
# Write the xml files that make up the XLSX OPC package.
|
|
138
144
|
self._write_content_types_file()
|
|
@@ -146,6 +152,8 @@ class Packager:
|
|
|
146
152
|
self._write_vml_files()
|
|
147
153
|
self._write_comment_files()
|
|
148
154
|
self._write_table_files()
|
|
155
|
+
self._write_pivot_table_files()
|
|
156
|
+
self._write_pivot_cache_files()
|
|
149
157
|
self._write_shared_strings_file()
|
|
150
158
|
self._write_styles_file()
|
|
151
159
|
self._write_custom_file()
|
|
@@ -467,6 +475,12 @@ class Packager:
|
|
|
467
475
|
for i in range(1, self.table_count + 1):
|
|
468
476
|
content._add_table_name("table" + str(i))
|
|
469
477
|
|
|
478
|
+
for i in range(1, self.pivot_table_count + 1):
|
|
479
|
+
content._add_pivot_table_name("pivotTable" + str(i))
|
|
480
|
+
|
|
481
|
+
for i in range(1, self.pivot_cache_count + 1):
|
|
482
|
+
content._add_pivot_cache_name("pivotCacheDefinition" + str(i))
|
|
483
|
+
|
|
470
484
|
for i in range(1, self.num_comment_files + 1):
|
|
471
485
|
content._add_comment_name("comments" + str(i))
|
|
472
486
|
|
|
@@ -554,6 +568,45 @@ class Packager:
|
|
|
554
568
|
table._assemble_xml_file()
|
|
555
569
|
index += 1
|
|
556
570
|
|
|
571
|
+
def _write_pivot_table_files(self) -> None:
|
|
572
|
+
# Write the pivot table files and their rels files.
|
|
573
|
+
index = 1
|
|
574
|
+
for worksheet in self.workbook.worksheets():
|
|
575
|
+
for pivot_table in worksheet.pivot_tables:
|
|
576
|
+
pivot_table._set_xml_writer(
|
|
577
|
+
self._filename(f"xl/pivotTables/pivotTable{index}.xml")
|
|
578
|
+
)
|
|
579
|
+
pivot_table._set_num_format_indices(self.workbook.xf_formats)
|
|
580
|
+
pivot_table._assemble_xml_file()
|
|
581
|
+
|
|
582
|
+
# Write the rels file that links the pivot table to its cache.
|
|
583
|
+
self._write_pivot_table_rels_file(pivot_table, index)
|
|
584
|
+
|
|
585
|
+
index += 1
|
|
586
|
+
|
|
587
|
+
def _write_pivot_table_rels_file(self, pivot_table: PivotTable, index: int) -> None:
|
|
588
|
+
# Write the pivot table .rels file, such as
|
|
589
|
+
# xl/pivotTables/_rels/pivotTable1.xml.rels.
|
|
590
|
+
rels = Relationships()
|
|
591
|
+
|
|
592
|
+
rels._add_document_relationship(
|
|
593
|
+
"/pivotCacheDefinition",
|
|
594
|
+
f"../pivotCache/pivotCacheDefinition{pivot_table.cache_id}.xml",
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
rels._set_xml_writer(
|
|
598
|
+
self._filename(f"xl/pivotTables/_rels/pivotTable{index}.xml.rels")
|
|
599
|
+
)
|
|
600
|
+
rels._assemble_xml_file()
|
|
601
|
+
|
|
602
|
+
def _write_pivot_cache_files(self) -> None:
|
|
603
|
+
# Write the pivot cache definition files.
|
|
604
|
+
for index, pivot_cache in enumerate(self.workbook.pivot_caches, 1):
|
|
605
|
+
pivot_cache._set_xml_writer(
|
|
606
|
+
self._filename(f"xl/pivotCache/pivotCacheDefinition{index}.xml")
|
|
607
|
+
)
|
|
608
|
+
pivot_cache._assemble_xml_file()
|
|
609
|
+
|
|
557
610
|
def _get_table_count(self) -> None:
|
|
558
611
|
# Count the table files. Required for the [Content_Types] file.
|
|
559
612
|
for worksheet in self.workbook.worksheets():
|
|
@@ -596,6 +649,11 @@ class Packager:
|
|
|
596
649
|
)
|
|
597
650
|
worksheet_index += 1
|
|
598
651
|
|
|
652
|
+
for i in range(1, self.pivot_cache_count + 1):
|
|
653
|
+
rels._add_document_relationship(
|
|
654
|
+
"/pivotCacheDefinition", f"pivotCache/pivotCacheDefinition{i}.xml"
|
|
655
|
+
)
|
|
656
|
+
|
|
599
657
|
rels._add_document_relationship("/theme", "theme/theme1.xml")
|
|
600
658
|
rels._add_document_relationship("/styles", "styles.xml")
|
|
601
659
|
|
|
@@ -638,6 +696,7 @@ class Packager:
|
|
|
638
696
|
+ worksheet.external_background_links
|
|
639
697
|
+ worksheet.external_table_links
|
|
640
698
|
+ worksheet.external_comment_links
|
|
699
|
+
+ worksheet.external_pivot_table_links
|
|
641
700
|
)
|
|
642
701
|
|
|
643
702
|
if not external_links:
|