XlsxWriter 3.3.2__tar.gz → 3.3.4__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.2 → xlsxwriter-3.3.4}/Changes +30 -0
- {xlsxwriter-3.3.2/xlsxwriter.egg-info → xlsxwriter-3.3.4}/PKG-INFO +20 -9
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/README.rst +19 -8
- xlsxwriter-3.3.4/examples/custom_ui.py +39 -0
- xlsxwriter-3.3.4/examples/pivot_table.py +287 -0
- xlsxwriter-3.3.4/examples/vbaProject_custom_ui.bin +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/pyproject.toml +1 -1
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/__init__.py +1 -1
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/contenttypes.py +19 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/exceptions.py +8 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/packager.py +82 -0
- xlsxwriter-3.3.4/xlsxwriter/pivot_cache.py +165 -0
- xlsxwriter-3.3.4/xlsxwriter/pivot_table.py +809 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/relationships.py +11 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/utility.py +1 -1
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/workbook.py +157 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/worksheet.py +163 -1
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4/xlsxwriter.egg-info}/PKG-INFO +20 -9
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter.egg-info/SOURCES.txt +5 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/LICENSE.txt +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/MANIFEST.in +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/array_formula.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/autofilter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/autofilter_data.txt +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/autofit.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/autofit_manually.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/background.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/cell_indentation.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_area.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_bar.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_clustered.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_column.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_combined.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_data_labels.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_data_table.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_data_tools.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_date_axis.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_doughnut.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_gauge.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_gradient.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_line.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_pareto.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_pattern.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_pie.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_radar.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_scatter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_secondary_axis.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_stock.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chart_styles.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/chartsheet.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/check_close.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/checkbox.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/colors.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/comments1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/comments2.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/conditional_format.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/context_manager.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/data_validate.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/datetimes.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/defined_name.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/demo.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/diagonal_border.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/django_simple.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/doc_properties.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/dynamic_arrays.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/embedded_images.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/headers_footers.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/hello_world.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/hide_row_col.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/hide_sheet.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/http_server.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/hyperlink.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/ignore_errors.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/images.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/images_bytesio.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/inheritance1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/inheritance2.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/lambda.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/macros.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/merge1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/merge_rich_string.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/outline.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/outline_collapsed.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_autofilter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_chart.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_chart_columns.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_chart_line.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_column_formats.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_conditional_format.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_datetime.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_header_format.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_multiple.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_percentage.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_positioning.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_simple.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/pandas_table.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/panes.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_chart.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_checkbox.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_conditional_format.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_format_custom.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_format_default.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_multiple.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_positioning.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_simple.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_sparklines.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/polars_xlsxwriter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/rich_strings.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/right_to_left.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/sensitivity_label.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/sparklines1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/sparklines2.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/tab_colors.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/tables.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/text_indent.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/textbox.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/theme_custom.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/theme_excel_2023.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/tutorial1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/tutorial2.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/tutorial3.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/unicode.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/unicode_polish_utf8.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/unicode_polish_utf8.txt +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/unicode_shift_jis.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/unicode_shift_jis.txt +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/user_types1.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/user_types2.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/user_types3.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/vbaProject.bin +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/vba_extract.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/watermark.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/examples/worksheet_protection.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/setup.cfg +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/app.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_area.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_bar.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_column.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_doughnut.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_line.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_pie.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_radar.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_scatter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_stock.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chart_title.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/chartsheet.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/color.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/comments.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/core.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/custom.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/drawing.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/feature_property_bag.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/format.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/image.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/metadata.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/rich_value.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/rich_value_rel.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/rich_value_structure.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/rich_value_types.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/shape.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/sharedstrings.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/styles.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/table.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/theme.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/url.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/vml.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter/xmlwriter.py +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter.egg-info/dependency_links.txt +0 -0
- {xlsxwriter-3.3.2 → xlsxwriter-3.3.4}/xlsxwriter.egg-info/top_level.txt +0 -0
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
|
|
2
|
+
Release 3.3.4 - November 22 2026
|
|
3
|
+
--------------------------------
|
|
4
|
+
|
|
5
|
+
* Added support for custom ribbon UI XML files via the :func:`add_custom_ui`
|
|
6
|
+
method. See :ref:`customui`.
|
|
7
|
+
|
|
8
|
+
:feature:`1086`.
|
|
9
|
+
|
|
10
|
+
* Fixed issue where datetimes on 1900-02-28 with a time after midnight were
|
|
11
|
+
written as 1900-02-29.
|
|
12
|
+
|
|
13
|
+
:issue:`1232`.
|
|
14
|
+
|
|
15
|
+
Release 3.3.3 - November 20 2026
|
|
16
|
+
--------------------------------
|
|
17
|
+
|
|
18
|
+
* Added support for worksheet pivot tables via the :func:`add_pivot_table`
|
|
19
|
+
method. Pivot tables can have row, column, filter and value fields, and the
|
|
20
|
+
value fields can have different functions, custom names and number formats.
|
|
21
|
+
The pivot table style, layout and grand totals can also be set. See
|
|
22
|
+
:ref:`pivot_tables` and :ref:`ex_pivot_table`.
|
|
23
|
+
|
|
24
|
+
**Note**, the pivot table data isn't stored in the file. Excel builds the
|
|
25
|
+
pivot table from the source data when the file is opened. As a result,
|
|
26
|
+
applications that don't refresh pivot tables on load will show an empty
|
|
27
|
+
pivot table, and Excel will ask to save the file on close even if no
|
|
28
|
+
changes were made. See :ref:`pivot_table_limitations` for details.
|
|
29
|
+
|
|
30
|
+
:feature:`1231`.
|
|
31
|
+
|
|
2
32
|
Release 3.3.2 - November 19 2026
|
|
3
33
|
--------------------------------
|
|
4
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xlsxwriter
|
|
3
|
-
Version: 3.3.
|
|
3
|
+
Version: 3.3.4
|
|
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
|
|
@@ -36,19 +36,30 @@ multiple worksheets and it supports features such as formatting and many more,
|
|
|
36
36
|
including:
|
|
37
37
|
|
|
38
38
|
* 100% compatible Excel XLSX files.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Support for writing all basic Excel data types.
|
|
40
|
+
* Full cell formatting support.
|
|
41
|
+
* Formula support, including new Excel 365 dynamic functions.
|
|
42
42
|
* Charts.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* Hyperlink support.
|
|
44
|
+
* Page/Printing Setup support.
|
|
45
|
+
* Merged ranges.
|
|
45
46
|
* Conditional formatting.
|
|
47
|
+
* Data validation and drop down lists.
|
|
48
|
+
* Cell comments.
|
|
49
|
+
* Textboxes.
|
|
50
|
+
* Checkboxes.
|
|
51
|
+
* Sparklines.
|
|
46
52
|
* Worksheet PNG/JPEG/GIF/BMP/WMF/EMF images.
|
|
53
|
+
* Workbook themes.
|
|
47
54
|
* Rich multi-format strings.
|
|
48
|
-
*
|
|
55
|
+
* Outline groupings.
|
|
56
|
+
* Defined names.
|
|
57
|
+
* Autofilters.
|
|
58
|
+
* Worksheet tables.
|
|
59
|
+
* Pivot tables.
|
|
49
60
|
* Integration with Pandas and Polars.
|
|
50
|
-
*
|
|
51
|
-
*
|
|
61
|
+
* Support for macros.
|
|
62
|
+
* Custom UI/Ribbon elements.
|
|
52
63
|
* Memory optimization mode for writing large files.
|
|
53
64
|
|
|
54
65
|
It supports Python 3.8+ and PyPy3 and uses standard libraries only.
|
|
@@ -9,19 +9,30 @@ multiple worksheets and it supports features such as formatting and many more,
|
|
|
9
9
|
including:
|
|
10
10
|
|
|
11
11
|
* 100% compatible Excel XLSX files.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Support for writing all basic Excel data types.
|
|
13
|
+
* Full cell formatting support.
|
|
14
|
+
* Formula support, including new Excel 365 dynamic functions.
|
|
15
15
|
* Charts.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Hyperlink support.
|
|
17
|
+
* Page/Printing Setup support.
|
|
18
|
+
* Merged ranges.
|
|
18
19
|
* Conditional formatting.
|
|
20
|
+
* Data validation and drop down lists.
|
|
21
|
+
* Cell comments.
|
|
22
|
+
* Textboxes.
|
|
23
|
+
* Checkboxes.
|
|
24
|
+
* Sparklines.
|
|
19
25
|
* Worksheet PNG/JPEG/GIF/BMP/WMF/EMF images.
|
|
26
|
+
* Workbook themes.
|
|
20
27
|
* Rich multi-format strings.
|
|
21
|
-
*
|
|
28
|
+
* Outline groupings.
|
|
29
|
+
* Defined names.
|
|
30
|
+
* Autofilters.
|
|
31
|
+
* Worksheet tables.
|
|
32
|
+
* Pivot tables.
|
|
22
33
|
* Integration with Pandas and Polars.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
34
|
+
* Support for macros.
|
|
35
|
+
* Custom UI/Ribbon elements.
|
|
25
36
|
* Memory optimization mode for writing large files.
|
|
26
37
|
|
|
27
38
|
It supports Python 3.8+ and PyPy3 and uses standard libraries only.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#######################################################################
|
|
2
|
+
#
|
|
3
|
+
# An example of adding a custom ribbon tab to an XlsxWriter file using a
|
|
4
|
+
# Custom UI XML file.
|
|
5
|
+
#
|
|
6
|
+
# The custom tab contains built-in Excel commands and a button that runs a
|
|
7
|
+
# macro from a VBA project file.
|
|
8
|
+
#
|
|
9
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
10
|
+
#
|
|
11
|
+
# Copyright (c) 2013-2026, John McNamara, jmcnamara@cpan.org
|
|
12
|
+
#
|
|
13
|
+
import xlsxwriter
|
|
14
|
+
|
|
15
|
+
# Note the file extension should be .xlsm.
|
|
16
|
+
workbook = xlsxwriter.Workbook("custom_ui.xlsm")
|
|
17
|
+
worksheet = workbook.add_worksheet()
|
|
18
|
+
|
|
19
|
+
worksheet.set_column("A:A", 50)
|
|
20
|
+
|
|
21
|
+
# Add the Custom UI XML file for the Excel 2010+ ribbon.
|
|
22
|
+
workbook.add_custom_ui("./customUI14.xml")
|
|
23
|
+
|
|
24
|
+
# Show some instructions for the end user.
|
|
25
|
+
bold = workbook.add_format({"bold": True})
|
|
26
|
+
worksheet.write("A1", "Use the 'My Ribbon' tab to sort the selected data.", bold)
|
|
27
|
+
|
|
28
|
+
# Add some data to sort.
|
|
29
|
+
for row, fruit in enumerate(["Pear", "Apple", "Orange", "Banana", "Grape"], 2):
|
|
30
|
+
worksheet.write(row, 0, fruit)
|
|
31
|
+
|
|
32
|
+
# Preselect the data so it is ready to sort.
|
|
33
|
+
worksheet.set_selection("A3:A7")
|
|
34
|
+
|
|
35
|
+
# Add the VBA project for the macro on the custom ribbon tab. This was extracted
|
|
36
|
+
# from an Excel file using the vba_extract tool.
|
|
37
|
+
workbook.add_vba_project("./vbaProject_custom_ui.bin")
|
|
38
|
+
|
|
39
|
+
workbook.close()
|
|
@@ -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()
|
|
Binary file
|
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -58,3 +62,7 @@ class FileSizeError(XlsxFileError):
|
|
|
58
62
|
|
|
59
63
|
class ThemeFileError(XlsxFileError):
|
|
60
64
|
"""Error when processing a custom theme file."""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class CustomUIFileError(XlsxFileError):
|
|
68
|
+
"""Error when processing a Custom UI file."""
|
|
@@ -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()
|
|
@@ -163,6 +171,7 @@ class Packager:
|
|
|
163
171
|
self._write_metadata_file()
|
|
164
172
|
self._write_feature_bag_property()
|
|
165
173
|
self._write_rich_value_files()
|
|
174
|
+
self._add_ribbons()
|
|
166
175
|
|
|
167
176
|
return self.filenames
|
|
168
177
|
|
|
@@ -467,6 +476,12 @@ class Packager:
|
|
|
467
476
|
for i in range(1, self.table_count + 1):
|
|
468
477
|
content._add_table_name("table" + str(i))
|
|
469
478
|
|
|
479
|
+
for i in range(1, self.pivot_table_count + 1):
|
|
480
|
+
content._add_pivot_table_name("pivotTable" + str(i))
|
|
481
|
+
|
|
482
|
+
for i in range(1, self.pivot_cache_count + 1):
|
|
483
|
+
content._add_pivot_cache_name("pivotCacheDefinition" + str(i))
|
|
484
|
+
|
|
470
485
|
for i in range(1, self.num_comment_files + 1):
|
|
471
486
|
content._add_comment_name("comments" + str(i))
|
|
472
487
|
|
|
@@ -554,6 +569,45 @@ class Packager:
|
|
|
554
569
|
table._assemble_xml_file()
|
|
555
570
|
index += 1
|
|
556
571
|
|
|
572
|
+
def _write_pivot_table_files(self) -> None:
|
|
573
|
+
# Write the pivot table files and their rels files.
|
|
574
|
+
index = 1
|
|
575
|
+
for worksheet in self.workbook.worksheets():
|
|
576
|
+
for pivot_table in worksheet.pivot_tables:
|
|
577
|
+
pivot_table._set_xml_writer(
|
|
578
|
+
self._filename(f"xl/pivotTables/pivotTable{index}.xml")
|
|
579
|
+
)
|
|
580
|
+
pivot_table._set_num_format_indices(self.workbook.xf_formats)
|
|
581
|
+
pivot_table._assemble_xml_file()
|
|
582
|
+
|
|
583
|
+
# Write the rels file that links the pivot table to its cache.
|
|
584
|
+
self._write_pivot_table_rels_file(pivot_table, index)
|
|
585
|
+
|
|
586
|
+
index += 1
|
|
587
|
+
|
|
588
|
+
def _write_pivot_table_rels_file(self, pivot_table: PivotTable, index: int) -> None:
|
|
589
|
+
# Write the pivot table .rels file, such as
|
|
590
|
+
# xl/pivotTables/_rels/pivotTable1.xml.rels.
|
|
591
|
+
rels = Relationships()
|
|
592
|
+
|
|
593
|
+
rels._add_document_relationship(
|
|
594
|
+
"/pivotCacheDefinition",
|
|
595
|
+
f"../pivotCache/pivotCacheDefinition{pivot_table.cache_id}.xml",
|
|
596
|
+
)
|
|
597
|
+
|
|
598
|
+
rels._set_xml_writer(
|
|
599
|
+
self._filename(f"xl/pivotTables/_rels/pivotTable{index}.xml.rels")
|
|
600
|
+
)
|
|
601
|
+
rels._assemble_xml_file()
|
|
602
|
+
|
|
603
|
+
def _write_pivot_cache_files(self) -> None:
|
|
604
|
+
# Write the pivot cache definition files.
|
|
605
|
+
for index, pivot_cache in enumerate(self.workbook.pivot_caches, 1):
|
|
606
|
+
pivot_cache._set_xml_writer(
|
|
607
|
+
self._filename(f"xl/pivotCache/pivotCacheDefinition{index}.xml")
|
|
608
|
+
)
|
|
609
|
+
pivot_cache._assemble_xml_file()
|
|
610
|
+
|
|
557
611
|
def _get_table_count(self) -> None:
|
|
558
612
|
# Count the table files. Required for the [Content_Types] file.
|
|
559
613
|
for worksheet in self.workbook.worksheets():
|
|
@@ -573,6 +627,9 @@ class Packager:
|
|
|
573
627
|
if self.workbook.custom_properties:
|
|
574
628
|
rels._add_document_relationship("/custom-properties", "docProps/custom.xml")
|
|
575
629
|
|
|
630
|
+
for part_name in self.workbook.custom_uis:
|
|
631
|
+
rels._add_custom_ui_relationship(part_name)
|
|
632
|
+
|
|
576
633
|
rels._set_xml_writer(self._filename("_rels/.rels"))
|
|
577
634
|
|
|
578
635
|
rels._assemble_xml_file()
|
|
@@ -596,6 +653,11 @@ class Packager:
|
|
|
596
653
|
)
|
|
597
654
|
worksheet_index += 1
|
|
598
655
|
|
|
656
|
+
for i in range(1, self.pivot_cache_count + 1):
|
|
657
|
+
rels._add_document_relationship(
|
|
658
|
+
"/pivotCacheDefinition", f"pivotCache/pivotCacheDefinition{i}.xml"
|
|
659
|
+
)
|
|
660
|
+
|
|
599
661
|
rels._add_document_relationship("/theme", "theme/theme1.xml")
|
|
600
662
|
rels._add_document_relationship("/styles", "styles.xml")
|
|
601
663
|
|
|
@@ -638,6 +700,7 @@ class Packager:
|
|
|
638
700
|
+ worksheet.external_background_links
|
|
639
701
|
+ worksheet.external_table_links
|
|
640
702
|
+ worksheet.external_comment_links
|
|
703
|
+
+ worksheet.external_pivot_table_links
|
|
641
704
|
)
|
|
642
705
|
|
|
643
706
|
if not external_links:
|
|
@@ -870,3 +933,22 @@ class Packager:
|
|
|
870
933
|
os_filename = BytesIO(vba_data)
|
|
871
934
|
|
|
872
935
|
self.filenames.append((os_filename, xml_vba_name, True))
|
|
936
|
+
|
|
937
|
+
def _add_ribbons(self) -> None:
|
|
938
|
+
# Write the Custom UI XML files.
|
|
939
|
+
custom_uis = self.workbook.custom_uis
|
|
940
|
+
|
|
941
|
+
if not custom_uis:
|
|
942
|
+
return
|
|
943
|
+
|
|
944
|
+
for part_name, (_, custom_ui_data) in custom_uis.items():
|
|
945
|
+
part_path = f"customUI/{part_name}.xml"
|
|
946
|
+
if not self.in_memory:
|
|
947
|
+
# In file mode we write the xml data to a file.
|
|
948
|
+
with open(self._filename(part_path), mode="wb") as custom_ui_file:
|
|
949
|
+
custom_ui_file.write(custom_ui_data)
|
|
950
|
+
|
|
951
|
+
else:
|
|
952
|
+
# Store the user's XML bytes unchanged.
|
|
953
|
+
os_filename = BytesIO(custom_ui_data)
|
|
954
|
+
self.filenames.append((os_filename, part_path, True))
|