XlsxWriter 3.2.0__tar.gz → 3.2.1__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.
Files changed (158) hide show
  1. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/Changes +21 -3
  2. {XlsxWriter-3.2.0/XlsxWriter.egg-info → XlsxWriter-3.2.1}/PKG-INFO +2 -1
  3. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1/XlsxWriter.egg-info}/PKG-INFO +2 -1
  4. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/XlsxWriter.egg-info/SOURCES.txt +2 -0
  5. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/autofilter.py +1 -1
  6. XlsxWriter-3.2.1/examples/autofit_manually.py +31 -0
  7. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/background.py +0 -1
  8. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_combined.py +1 -1
  9. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_date_axis.py +1 -0
  10. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_stock.py +1 -0
  11. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_styles.py +1 -1
  12. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/check_close.py +3 -3
  13. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/data_validate.py +1 -0
  14. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/datetimes.py +1 -0
  15. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/defined_name.py +0 -1
  16. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/demo.py +0 -1
  17. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/django_simple.py +5 -1
  18. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/dynamic_arrays.py +2 -2
  19. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/embedded_images.py +5 -2
  20. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/images.py +0 -1
  21. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/images_bytesio.py +0 -1
  22. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/inheritance1.py +3 -4
  23. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/inheritance2.py +6 -7
  24. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/merge1.py +0 -1
  25. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/merge_rich_string.py +0 -1
  26. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_chart.py +0 -1
  27. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_chart_line.py +2 -1
  28. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_conditional_format.py +0 -1
  29. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_datetime.py +2 -1
  30. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_multiple.py +0 -1
  31. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_percentage.py +0 -1
  32. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_positioning.py +0 -1
  33. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_simple.py +0 -1
  34. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_chart.py +2 -1
  35. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_format_custom.py +1 -0
  36. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_format_default.py +1 -0
  37. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_multiple.py +2 -1
  38. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_positioning.py +3 -2
  39. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_sparklines.py +1 -2
  40. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_xlsxwriter.py +2 -1
  41. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/rich_strings.py +2 -2
  42. XlsxWriter-3.2.1/examples/sensitivity_label.py +29 -0
  43. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/tutorial3.py +1 -0
  44. XlsxWriter-3.2.1/examples/unicode_polish_utf8.py +38 -0
  45. XlsxWriter-3.2.1/examples/unicode_shift_jis.py +38 -0
  46. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/user_types1.py +4 -3
  47. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/user_types2.py +4 -3
  48. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/user_types3.py +3 -3
  49. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/vba_extract.py +14 -14
  50. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/setup.py +3 -2
  51. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/__init__.py +1 -1
  52. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/app.py +2 -2
  53. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart.py +74 -79
  54. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_area.py +3 -3
  55. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_bar.py +6 -4
  56. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_column.py +2 -2
  57. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_doughnut.py +6 -5
  58. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_line.py +2 -2
  59. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_pie.py +7 -5
  60. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_radar.py +2 -2
  61. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_scatter.py +5 -3
  62. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chart_stock.py +4 -4
  63. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/chartsheet.py +2 -2
  64. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/comments.py +7 -5
  65. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/contenttypes.py +21 -20
  66. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/core.py +1 -1
  67. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/custom.py +1 -1
  68. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/drawing.py +18 -27
  69. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/format.py +229 -66
  70. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/metadata.py +6 -6
  71. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/packager.py +14 -13
  72. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/relationships.py +7 -7
  73. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/rich_value.py +1 -1
  74. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/rich_value_rel.py +1 -1
  75. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/rich_value_structure.py +3 -3
  76. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/rich_value_types.py +0 -14
  77. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/shape.py +23 -22
  78. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/sharedstrings.py +9 -9
  79. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/styles.py +2 -5
  80. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/table.py +1 -1
  81. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/theme.py +4 -2
  82. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/utility.py +139 -54
  83. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/vml.py +20 -34
  84. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/workbook.py +85 -51
  85. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/worksheet.py +381 -337
  86. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/xmlwriter.py +32 -32
  87. XlsxWriter-3.2.0/examples/unicode_polish_utf8.py +0 -38
  88. XlsxWriter-3.2.0/examples/unicode_shift_jis.py +0 -38
  89. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/LICENSE.txt +0 -0
  90. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/MANIFEST.in +0 -0
  91. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/README.rst +0 -0
  92. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/XlsxWriter.egg-info/dependency_links.txt +0 -0
  93. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/XlsxWriter.egg-info/top_level.txt +0 -0
  94. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/array_formula.py +0 -0
  95. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/autofilter_data.txt +0 -0
  96. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/autofit.py +0 -0
  97. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/cell_indentation.py +0 -0
  98. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart.py +0 -0
  99. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_area.py +0 -0
  100. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_bar.py +0 -0
  101. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_clustered.py +0 -0
  102. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_column.py +0 -0
  103. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_data_labels.py +0 -0
  104. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_data_table.py +0 -0
  105. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_data_tools.py +0 -0
  106. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_doughnut.py +0 -0
  107. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_gauge.py +0 -0
  108. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_gradient.py +0 -0
  109. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_line.py +0 -0
  110. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_pareto.py +0 -0
  111. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_pattern.py +0 -0
  112. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_pie.py +0 -0
  113. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_radar.py +0 -0
  114. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_scatter.py +0 -0
  115. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chart_secondary_axis.py +0 -0
  116. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/chartsheet.py +0 -0
  117. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/comments1.py +0 -0
  118. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/comments2.py +0 -0
  119. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/conditional_format.py +0 -0
  120. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/context_manager.py +0 -0
  121. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/diagonal_border.py +0 -0
  122. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/doc_properties.py +0 -0
  123. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/headers_footers.py +0 -0
  124. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/hello_world.py +0 -0
  125. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/hide_row_col.py +0 -0
  126. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/hide_sheet.py +0 -0
  127. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/http_server.py +1 -1
  128. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/hyperlink.py +0 -0
  129. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/ignore_errors.py +0 -0
  130. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/lambda.py +0 -0
  131. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/macros.py +0 -0
  132. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/outline.py +0 -0
  133. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/outline_collapsed.py +0 -0
  134. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_autofilter.py +0 -0
  135. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_chart_columns.py +0 -0
  136. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_column_formats.py +0 -0
  137. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_header_format.py +0 -0
  138. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/pandas_table.py +0 -0
  139. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/panes.py +0 -0
  140. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_conditional_format.py +0 -0
  141. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/polars_simple.py +0 -0
  142. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/right_to_left.py +0 -0
  143. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/sparklines1.py +0 -0
  144. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/sparklines2.py +0 -0
  145. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/tab_colors.py +0 -0
  146. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/tables.py +0 -0
  147. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/text_indent.py +0 -0
  148. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/textbox.py +0 -0
  149. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/tutorial1.py +0 -0
  150. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/tutorial2.py +0 -0
  151. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/unicode.py +0 -0
  152. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/unicode_polish_utf8.txt +0 -0
  153. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/unicode_shift_jis.txt +0 -0
  154. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/vbaProject.bin +0 -0
  155. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/watermark.py +0 -0
  156. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/examples/worksheet_protection.py +0 -0
  157. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/setup.cfg +0 -0
  158. {XlsxWriter-3.2.0 → XlsxWriter-3.2.1}/xlsxwriter/exceptions.py +0 -0
@@ -1,10 +1,28 @@
1
+ Release 3.2.1 - January 22 2025
2
+ --------------------------------
3
+
4
+ Added improvements to ``autofit()``.
5
+
6
+ * Added the optional ``max_width`` parameter to the :func:`autofit()` method to
7
+ work around the issue where the autofit width is too big.
8
+
9
+ Excel autofits very long strings up to limit of 1790 pixels/255 characters.
10
+ This is often too wide to display on a single screen at normal zoom. As such
11
+ the ``max_width`` parameter is provided to enable a smaller upper pixel limit
12
+ for autofitting long strings. See :func:`autofit()`.
13
+
14
+ :feature:`1106`.
15
+
16
+ * Added the :func:`cell_autofit_width` utility function to allow users to
17
+ calculate the auto-fit width for a cell value. This allows the user to
18
+ implement their own auto-fit logic. See :ref:`ex_autofit_manually`.
1
19
 
2
20
 
3
21
  Release 3.2.0 - February 17 2024
4
22
  --------------------------------
5
23
 
6
24
  This is the 10th anniversary release of XlsxWriter. Version 0.0.1 was released
7
- on February 17 2013. Since they there have been 167 releases, 25,000 lines of
25
+ on February 17 2013. Since then there have been 167 releases, 25,000 lines of
8
26
  code, 1600 test cases, 700 pages of documentation, 71,000 users on GitHub, 50
9
27
  contributors, 1000 closed issues and 150 million yearly downloads. Thanks to
10
28
  everyone who has contributed code, given feedback or just used the library.
@@ -118,9 +136,9 @@ Release 3.0.9 - March 10 2023
118
136
  -----------------------------
119
137
 
120
138
  * Add documentation and examples on :ref:`ewx_polars` to demonstrate new `Polars
121
- <https://www.pola.rs>`_ integration of XlsxWriter in `write_excel()`_.
139
+ <https://pola.rs/>`_ integration of XlsxWriter in `write_excel()`_.
122
140
 
123
- .. _write_excel(): https://pola-rs.github.io/polars/py-polars/html/reference/api/polars.DataFrame.write_excel.html#polars.DataFrame.write_excel
141
+ .. _write_excel(): https://docs.pola.rs/py-polars/html/reference/api/polars.DataFrame.write_excel.html
124
142
 
125
143
  * Add fix for rare issue with duplicate number formats.
126
144
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: XlsxWriter
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: A Python module for creating Excel XLSX files.
5
5
  Home-page: https://github.com/jmcnamara/XlsxWriter
6
6
  Author: John McNamara
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Requires-Python: >=3.6
22
23
  License-File: LICENSE.txt
23
24
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: XlsxWriter
3
- Version: 3.2.0
3
+ Version: 3.2.1
4
4
  Summary: A Python module for creating Excel XLSX files.
5
5
  Home-page: https://github.com/jmcnamara/XlsxWriter
6
6
  Author: John McNamara
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Requires-Python: >=3.6
22
23
  License-File: LICENSE.txt
23
24
 
@@ -12,6 +12,7 @@ examples/array_formula.py
12
12
  examples/autofilter.py
13
13
  examples/autofilter_data.txt
14
14
  examples/autofit.py
15
+ examples/autofit_manually.py
15
16
  examples/background.py
16
17
  examples/cell_indentation.py
17
18
  examples/chart.py
@@ -93,6 +94,7 @@ examples/polars_sparklines.py
93
94
  examples/polars_xlsxwriter.py
94
95
  examples/rich_strings.py
95
96
  examples/right_to_left.py
97
+ examples/sensitivity_label.py
96
98
  examples/sparklines1.py
97
99
  examples/sparklines2.py
98
100
  examples/tab_colors.py
@@ -26,7 +26,7 @@ worksheet7 = workbook.add_worksheet()
26
26
  bold = workbook.add_format({"bold": 1})
27
27
 
28
28
  # Open a text file with autofilter example data.
29
- textfile = open("autofilter_data.txt")
29
+ textfile = open("autofilter_data.txt", encoding="utf-8")
30
30
 
31
31
  # Read the headers from the first line of the input file.
32
32
  headers = textfile.readline().strip("\n").split()
@@ -0,0 +1,31 @@
1
+ ##############################################################################
2
+ #
3
+ # The following example demonstrates manually auto-fitting the the width of a
4
+ # column in Excel based on the maximum string width. The worksheet ``autofit()``
5
+ # method will do this automatically but occasionally you may need to control the
6
+ # maximum and minimum column widths yourself.
7
+ #
8
+ # SPDX-License-Identifier: BSD-2-Clause
9
+ # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
10
+ #
11
+ from functools import reduce
12
+
13
+ import xlsxwriter
14
+ from xlsxwriter.utility import cell_autofit_width
15
+
16
+ workbook = xlsxwriter.Workbook("autofit.xlsx")
17
+ worksheet = workbook.add_worksheet()
18
+
19
+ # Some string data to write.
20
+ cities = ["Addis Ababa", "Buenos Aires", "Cairo", "Dhaka"]
21
+
22
+ # Write the strings:
23
+ worksheet.write_column(0, 0, cities)
24
+
25
+ # Find the maximum column width in pixels.
26
+ max_width = reduce(max, map(cell_autofit_width, cities))
27
+
28
+ # Set the column width as if it was auto-fitted.
29
+ worksheet.set_column_pixels(0, 0, max_width)
30
+
31
+ workbook.close()
@@ -8,7 +8,6 @@
8
8
  #
9
9
  import xlsxwriter
10
10
 
11
-
12
11
  # Create an new Excel file and add a worksheet.
13
12
  workbook = xlsxwriter.Workbook("background.xlsx")
14
13
  worksheet = workbook.add_worksheet()
@@ -43,7 +43,7 @@ column_chart1.add_series(
43
43
  }
44
44
  )
45
45
 
46
- # Create a new column chart. This will use this as the secondary chart.
46
+ # Create a new line chart. This will use this as the secondary chart.
47
47
  line_chart1 = workbook.add_chart({"type": "line"})
48
48
 
49
49
  # Configure the data series for the secondary chart.
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  from datetime import date
11
+
11
12
  import xlsxwriter
12
13
 
13
14
  workbook = xlsxwriter.Workbook("chart_date_axis.xlsx")
@@ -6,6 +6,7 @@
6
6
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7
7
  #
8
8
  from datetime import datetime
9
+
9
10
  import xlsxwriter
10
11
 
11
12
  workbook = xlsxwriter.Workbook("chart_stock.xlsx")
@@ -25,7 +25,7 @@ for chart_type in chart_types:
25
25
  for col_num in range(0, 64, 8):
26
26
  chart = workbook.add_chart({"type": chart_type})
27
27
  chart.add_series({"values": "=Data!$A$1:$A$6"})
28
- chart.set_title({"name": "Style %d" % style_number})
28
+ chart.set_title({"name": f"Style {style_number}"})
29
29
  chart.set_legend({"none": True})
30
30
  chart.set_style(style_number)
31
31
 
@@ -20,9 +20,9 @@ while True:
20
20
  workbook.close()
21
21
  except xlsxwriter.exceptions.FileCreateError as e:
22
22
  decision = input(
23
- "Exception caught in workbook.close(): %s\n"
24
- "Please close the file if it is open in Excel.\n"
25
- "Try to write file again? [Y/n]: " % e
23
+ f"Exception caught in workbook.close(): {e}\n"
24
+ f"Please close the file if it is open in Excel.\n"
25
+ f"Try to write file again? [Y/n]: "
26
26
  )
27
27
  if decision != "n":
28
28
  continue
@@ -12,6 +12,7 @@
12
12
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
13
13
  #
14
14
  from datetime import date, time
15
+
15
16
  import xlsxwriter
16
17
 
17
18
  workbook = xlsxwriter.Workbook("data_validate.xlsx")
@@ -7,6 +7,7 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
  from datetime import datetime
10
+
10
11
  import xlsxwriter
11
12
 
12
13
  # Create a workbook and add a worksheet.
@@ -10,7 +10,6 @@
10
10
  #
11
11
  import xlsxwriter
12
12
 
13
-
14
13
  workbook = xlsxwriter.Workbook("defined_name.xlsx")
15
14
  worksheet1 = workbook.add_worksheet()
16
15
  worksheet2 = workbook.add_worksheet()
@@ -7,7 +7,6 @@
7
7
  #
8
8
  import xlsxwriter
9
9
 
10
-
11
10
  # Create an new Excel file and add a worksheet.
12
11
  workbook = xlsxwriter.Workbook("demo.xlsx")
13
12
  worksheet = workbook.add_worksheet()
@@ -6,9 +6,13 @@
6
6
  # SPDX-License-Identifier: BSD-2-Clause
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
+ # pylint: skip-file
10
+
9
11
  import io
12
+
10
13
  from django.http import HttpResponse
11
14
  from django.views.generic import View
15
+
12
16
  import xlsxwriter
13
17
 
14
18
 
@@ -49,6 +53,6 @@ class MyView(View):
49
53
  output,
50
54
  content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
51
55
  )
52
- response["Content-Disposition"] = "attachment; filename=%s" % filename
56
+ response["Content-Disposition"] = f"attachment; filename={filename}"
53
57
 
54
58
  return response
@@ -26,8 +26,8 @@ def main():
26
26
  worksheet9 = workbook.add_worksheet("Spill ranges")
27
27
  worksheet10 = workbook.add_worksheet("Older functions")
28
28
 
29
- header1 = workbook.add_format({"fg_color": "#74AC4C", "color": "#FFFFFF"})
30
- header2 = workbook.add_format({"fg_color": "#528FD3", "color": "#FFFFFF"})
29
+ header1 = workbook.add_format({"fg_color": "#74AC4C", "font_color": "#FFFFFF"})
30
+ header2 = workbook.add_format({"fg_color": "#528FD3", "font_color": "#FFFFFF"})
31
31
 
32
32
  #
33
33
  # Example of using the FILTER() function.
@@ -1,14 +1,17 @@
1
1
  ##############################################################################
2
2
  #
3
3
  # An example of embedding images into a worksheet cells using the XlsxWriter
4
- # Python module. This is equivalent to Excel's "Place in cell" image insert.
4
+ # Python module.
5
+ #
6
+ # This is the equivalent of Excel's menu option to insert an image using the
7
+ # option to "Place in Cell" which is only available in Excel 365 versions from
8
+ # 2023 onwards. For older versions of Excel a ``#VALUE!`` error is displayed.
5
9
  #
6
10
  # SPDX-License-Identifier: BSD-2-Clause
7
11
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
12
  #
9
13
  import xlsxwriter
10
14
 
11
-
12
15
  # Create an new Excel file and add a worksheet.
13
16
  workbook = xlsxwriter.Workbook("embedded_images.xlsx")
14
17
  worksheet = workbook.add_worksheet()
@@ -8,7 +8,6 @@
8
8
  #
9
9
  import xlsxwriter
10
10
 
11
-
12
11
  # Create an new Excel file and add a worksheet.
13
12
  workbook = xlsxwriter.Workbook("images.xlsx")
14
13
  worksheet = workbook.add_worksheet()
@@ -10,7 +10,6 @@
10
10
  from io import BytesIO
11
11
  from urllib.request import urlopen
12
12
 
13
-
14
13
  import xlsxwriter
15
14
 
16
15
  # Create the workbook and add a worksheet.
@@ -7,8 +7,7 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
  from xlsxwriter.workbook import Workbook
10
- from xlsxwriter.worksheet import Worksheet
11
- from xlsxwriter.worksheet import convert_cell_args
10
+ from xlsxwriter.worksheet import Worksheet, convert_cell_args
12
11
 
13
12
 
14
13
  class MyWorksheet(Worksheet):
@@ -28,7 +27,7 @@ class MyWorksheet(Worksheet):
28
27
  return self.write_string(row, col, data)
29
28
  else:
30
29
  # Call the parent version of write() as usual for other data.
31
- return super(MyWorksheet, self).write(row, col, *args)
30
+ return super().write(row, col, *args)
32
31
 
33
32
 
34
33
  class MyWorkbook(Workbook):
@@ -40,7 +39,7 @@ class MyWorkbook(Workbook):
40
39
 
41
40
  def add_worksheet(self, name=None):
42
41
  # Overwrite add_worksheet() to create a MyWorksheet object.
43
- worksheet = super(MyWorkbook, self).add_worksheet(name, MyWorksheet)
42
+ worksheet = super().add_worksheet(name, MyWorksheet)
44
43
 
45
44
  return worksheet
46
45
 
@@ -15,18 +15,17 @@
15
15
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
16
16
  #
17
17
  from xlsxwriter.workbook import Workbook
18
- from xlsxwriter.worksheet import Worksheet
19
- from xlsxwriter.worksheet import convert_cell_args
18
+ from xlsxwriter.worksheet import Worksheet, convert_cell_args
20
19
 
21
20
 
22
- def excel_string_width(str):
21
+ def excel_string_width(string):
23
22
  """
24
23
  Calculate the length of the string in Excel character units. This is only
25
24
  an example and won't give accurate results. It will need to be replaced
26
25
  by something more rigorous.
27
26
 
28
27
  """
29
- string_width = len(str)
28
+ string_width = len(string)
30
29
 
31
30
  if string_width == 0:
32
31
  return 0
@@ -63,7 +62,7 @@ class MyWorksheet(Worksheet):
63
62
  self.max_column_widths[col] = string_width
64
63
 
65
64
  # Now call the parent version of write_string() as usual.
66
- return super(MyWorksheet, self).write_string(row, col, string, cell_format)
65
+ return super().write_string(row, col, string, cell_format)
67
66
 
68
67
 
69
68
  class MyWorkbook(Workbook):
@@ -76,7 +75,7 @@ class MyWorkbook(Workbook):
76
75
  def add_worksheet(self, name=None):
77
76
  # Overwrite add_worksheet() to create a MyWorksheet object.
78
77
  # Also add an Worksheet attribute to store the column widths.
79
- worksheet = super(MyWorkbook, self).add_worksheet(name, MyWorksheet)
78
+ worksheet = super().add_worksheet(name, MyWorksheet)
80
79
  worksheet.max_column_widths = {}
81
80
 
82
81
  return worksheet
@@ -90,7 +89,7 @@ class MyWorkbook(Workbook):
90
89
  for column, width in worksheet.max_column_widths.items():
91
90
  worksheet.set_column(column, column, width)
92
91
 
93
- return super(MyWorkbook, self).close()
92
+ return super().close()
94
93
 
95
94
 
96
95
  # Create a new MyWorkbook object.
@@ -7,7 +7,6 @@
7
7
  #
8
8
  import xlsxwriter
9
9
 
10
-
11
10
  # Create an new Excel file and add a worksheet.
12
11
  workbook = xlsxwriter.Workbook("merge1.xlsx")
13
12
  worksheet = workbook.add_worksheet()
@@ -8,7 +8,6 @@
8
8
  #
9
9
  import xlsxwriter
10
10
 
11
-
12
11
  # Create an new Excel file and add a worksheet.
13
12
  workbook = xlsxwriter.Workbook("merge_rich_string.xlsx")
14
13
  worksheet = workbook.add_worksheet()
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create a Pandas dataframe from some data.
14
13
  df = pd.DataFrame({"Data": [10, 20, 30, 20, 15, 30, 45]})
15
14
 
@@ -7,9 +7,10 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
 
10
- import pandas as pd
11
10
  import random
12
11
 
12
+ import pandas as pd
13
+
13
14
  # Create some sample data to plot.
14
15
  categories = ["Node 1", "Node 2", "Node 3", "Node 4"]
15
16
  index_1 = range(0, 21, 1)
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create a Pandas dataframe from some data.
14
13
  df = pd.DataFrame({"Data": [10, 20, 30, 20, 15, 30, 45]})
15
14
 
@@ -7,8 +7,9 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
 
10
+ from datetime import date, datetime
11
+
10
12
  import pandas as pd
11
- from datetime import datetime, date
12
13
 
13
14
  # Create a Pandas dataframe from some datetime data.
14
15
  df = pd.DataFrame(
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create some Pandas dataframes from some data.
14
13
  df1 = pd.DataFrame({"Data": [11, 12, 13, 14]})
15
14
  df2 = pd.DataFrame({"Data": [21, 22, 23, 24]})
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create a Pandas dataframe from some data.
14
13
  df = pd.DataFrame({"Names": ["Anna", "Arek", "Arun"], "Grade": ["100%", "70%", "85%"]})
15
14
 
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create some Pandas dataframes from some data.
14
13
  df1 = pd.DataFrame({"Data": [11, 12, 13, 14]})
15
14
  df2 = pd.DataFrame({"Data": [21, 22, 23, 24]})
@@ -9,7 +9,6 @@
9
9
 
10
10
  import pandas as pd
11
11
 
12
-
13
12
  # Create a Pandas dataframe from some data.
14
13
  df = pd.DataFrame({"Data": [10, 20, 30, 20, 15, 30, 45]})
15
14
 
@@ -7,9 +7,10 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
 
10
- import xlsxwriter
11
10
  import polars as pl
12
11
 
12
+ import xlsxwriter
13
+
13
14
  df = pl.DataFrame({"Data": [10, 20, 30, 20, 15, 30, 45]})
14
15
 
15
16
  with xlsxwriter.Workbook("polars_chart.xlsx") as workbook:
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  from datetime import date
11
+
11
12
  import polars as pl
12
13
 
13
14
  # Create a Pandas dataframe with some sample data.
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  from datetime import date
11
+
11
12
  import polars as pl
12
13
 
13
14
  # Create a Pandas dataframe with some sample data.
@@ -7,9 +7,10 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
 
10
- import xlsxwriter
11
10
  import polars as pl
12
11
 
12
+ import xlsxwriter
13
+
13
14
  # Create some Polars dataframes from some data.
14
15
  df1 = pl.DataFrame({"Data": [11, 12, 13, 14]})
15
16
  df2 = pl.DataFrame({"Data": [21, 22, 23, 24]})
@@ -7,9 +7,10 @@
7
7
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
8
8
  #
9
9
 
10
- import xlsxwriter
11
10
  import polars as pl
12
11
 
12
+ import xlsxwriter
13
+
13
14
  # Create some Polars dataframes from some data.
14
15
  df1 = pl.DataFrame({"Data": [11, 12, 13, 14]})
15
16
  df2 = pl.DataFrame({"Data": [21, 22, 23, 24]})
@@ -28,5 +29,5 @@ with xlsxwriter.Workbook("polars_positioning.xlsx") as workbook:
28
29
 
29
30
  # Write the dataframe without the header.
30
31
  df4.write_excel(
31
- workbook=workbook, worksheet="Sheet1", position="C8", has_header=False
32
+ workbook=workbook, worksheet="Sheet1", position="C8", include_header=False
32
33
  )
@@ -8,7 +8,6 @@
8
8
  #
9
9
 
10
10
  import polars as pl
11
- from polars.datatypes import INTEGER_DTYPES
12
11
 
13
12
  df = pl.DataFrame(
14
13
  {
@@ -26,7 +25,7 @@ df.write_excel(
26
25
  # Set an alternative table style.
27
26
  table_style="Table Style Light 2",
28
27
  # Specify an Excel number format for integer types.
29
- dtype_formats={INTEGER_DTYPES: "#,##0_);(#,##0)"},
28
+ dtype_formats={pl.Int32: "#,##0_);(#,##0)"},
30
29
  # Configure sparklines to the dataframe.
31
30
  sparklines={
32
31
  # We use the default options with just the source columns.
@@ -6,9 +6,10 @@
6
6
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7
7
  #
8
8
 
9
- import xlsxwriter
10
9
  import polars as pl
11
10
 
11
+ import xlsxwriter
12
+
12
13
  with xlsxwriter.Workbook("polars_xlsxwriter.xlsx") as workbook:
13
14
  # Create a new worksheet.
14
15
  worksheet = workbook.add_worksheet()
@@ -16,8 +16,8 @@ worksheet.set_column("A:A", 30)
16
16
  # Set up some formats to use.
17
17
  bold = workbook.add_format({"bold": True})
18
18
  italic = workbook.add_format({"italic": True})
19
- red = workbook.add_format({"color": "red"})
20
- blue = workbook.add_format({"color": "blue"})
19
+ red = workbook.add_format({"font_color": "red"})
20
+ blue = workbook.add_format({"font_color": "blue"})
21
21
  center = workbook.add_format({"align": "center"})
22
22
  superscript = workbook.add_format({"font_script": 1})
23
23
 
@@ -0,0 +1,29 @@
1
+ ##############################################################################
2
+ #
3
+ # An example of adding a Sensitivity Label to an XlsxWriter file.
4
+ #
5
+ # SPDX-License-Identifier: BSD-2-Clause
6
+ # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ import xlsxwriter
9
+
10
+ workbook = xlsxwriter.Workbook("sensitivity_label.xlsx")
11
+ worksheet = workbook.add_worksheet()
12
+
13
+ # Metadata extracted from a company specific file.
14
+ company_guid = "2096f6a2-d2f7-48be-b329-b73aaa526e5d"
15
+ site_id = "cb46c030-1825-4e81-a295-151c039dbf02"
16
+ action_id = "88124cf5-1340-457d-90e1-0000a9427c99"
17
+
18
+ # Add the document properties. Note that these should all be in text format.
19
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_Enabled", "true", "text")
20
+ workbook.set_custom_property(
21
+ f"MSIP_Label_{company_guid}_SetDate", "2024-01-01T12:00:00Z", "text"
22
+ )
23
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_Method", "Privileged", "text")
24
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_Name", "Confidential", "text")
25
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_SiteId", site_id, "text")
26
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_ActionId", action_id, "text")
27
+ workbook.set_custom_property(f"MSIP_Label_{company_guid}_ContentBits", "2", "text")
28
+
29
+ workbook.close()
@@ -10,6 +10,7 @@
10
10
  # Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
11
11
  #
12
12
  from datetime import datetime
13
+
13
14
  import xlsxwriter
14
15
 
15
16
  # Create a workbook and add a worksheet.