odfdo 3.26.3__tar.gz → 3.27.2__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 (131) hide show
  1. {odfdo-3.26.3 → odfdo-3.27.2}/PKG-INFO +6 -6
  2. {odfdo-3.26.3 → odfdo-3.27.2}/README.md +5 -5
  3. {odfdo-3.26.3 → odfdo-3.27.2}/pyproject.toml +8 -8
  4. {odfdo-3.26.3 → odfdo-3.27.2}/pyproject.toml.orig +8 -8
  5. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/document.py +22 -2
  6. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_md.py +2 -1
  7. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/office_forms.py +1 -3
  8. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/folder.py +12 -10
  9. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/table.py +76 -23
  10. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/table_cache.py +15 -1
  11. odfdo-3.26.3/src/odfdo/container.py.orig +0 -1952
  12. {odfdo-3.26.3 → odfdo-3.27.2}/LICENSE +0 -0
  13. {odfdo-3.26.3 → odfdo-3.27.2}/NOTICE.txt +0 -0
  14. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/__init__.py +0 -0
  15. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/annotation.py +0 -0
  16. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/body.py +0 -0
  17. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/bookmark.py +0 -0
  18. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/cell.py +0 -0
  19. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/column.py +0 -0
  20. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/config_elements.py +0 -0
  21. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/const.py +0 -0
  22. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/container.py +0 -0
  23. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/content.py +0 -0
  24. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/datatype.py +0 -0
  25. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/draw_page.py +0 -0
  26. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/element.py +0 -0
  27. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/element_strip.py +0 -0
  28. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/element_typed.py +0 -0
  29. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/elements_between.py +0 -0
  30. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/form.py +0 -0
  31. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/form_controls.py +0 -0
  32. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/form_controls_mixins.py +0 -0
  33. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/form_properties.py +0 -0
  34. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/frame.py +0 -0
  35. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/header.py +0 -0
  36. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/header_rows.py +0 -0
  37. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/image.py +0 -0
  38. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/line_break.py +0 -0
  39. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/link.py +0 -0
  40. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/list.py +0 -0
  41. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/manifest.py +0 -0
  42. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/master_page.py +0 -0
  43. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta.py +0 -0
  44. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta_auto_reload.py +0 -0
  45. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta_field.py +0 -0
  46. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta_hyperlink_behaviour.py +0 -0
  47. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta_template.py +0 -0
  48. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/meta_user_defined.py +0 -0
  49. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_dc_creator.py +0 -0
  50. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_dc_date.py +0 -0
  51. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_link.py +0 -0
  52. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_list.py +0 -0
  53. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_named_range.py +0 -0
  54. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_paragraph.py +0 -0
  55. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_paragraph_formatted.py +0 -0
  56. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/mixin_toc.py +0 -0
  57. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/named_range.py +0 -0
  58. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/note.py +0 -0
  59. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/page_layout.py +0 -0
  60. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/paragraph.py +0 -0
  61. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/presentation_notes.py +0 -0
  62. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/py.typed +0 -0
  63. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/reference.py +0 -0
  64. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/row.py +0 -0
  65. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/row_group.py +0 -0
  66. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/ruby_base.py +0 -0
  67. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/__init__.py +0 -0
  68. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/diff.py +0 -0
  69. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/flat.py +0 -0
  70. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/from_csv.py +0 -0
  71. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/from_json.py +0 -0
  72. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/headers.py +0 -0
  73. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/highlight.py +0 -0
  74. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/meta_print.py +0 -0
  75. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/meta_update.py +0 -0
  76. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/replace.py +0 -0
  77. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/show.py +0 -0
  78. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/styles.py +0 -0
  79. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/table_shrink.py +0 -0
  80. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/to_csv.py +0 -0
  81. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/to_json.py +0 -0
  82. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/to_markdown.py +0 -0
  83. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/scripts/userfield.py +0 -0
  84. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/section.py +0 -0
  85. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/security.py +0 -0
  86. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/settings.py +0 -0
  87. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/shapes.py +0 -0
  88. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/smil.py +0 -0
  89. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/spacer.py +0 -0
  90. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/span.py +0 -0
  91. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style.py +0 -0
  92. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style_base.py +0 -0
  93. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style_containers.py +0 -0
  94. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style_defaults.py +0 -0
  95. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style_props.py +0 -0
  96. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/style_utils.py +0 -0
  97. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/styles.py +0 -0
  98. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/svg.py +0 -0
  99. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/tab.py +0 -0
  100. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/table_serializer.py +0 -0
  101. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/__init__.py +0 -0
  102. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/drawing.otg +0 -0
  103. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/lpod_styles.odt +0 -0
  104. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/presentation.otp +0 -0
  105. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/spreadsheet.ots +0 -0
  106. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/templates/text.ott +0 -0
  107. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/text_index.py +0 -0
  108. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/toc.py +0 -0
  109. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/tracked_changes.py +0 -0
  110. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/unit.py +0 -0
  111. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/user_field.py +0 -0
  112. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/user_field_declaration.py +0 -0
  113. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/__init__.py +0 -0
  114. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/blob.py +0 -0
  115. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/color.py +0 -0
  116. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/coordinates.py +0 -0
  117. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/css3_colormap.py +0 -0
  118. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/formula.py +0 -0
  119. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/isiterable.py +0 -0
  120. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/json_formater.py +0 -0
  121. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/remove_tree.py +0 -0
  122. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/rfc3066.py +0 -0
  123. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/script_utils.py +0 -0
  124. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/str_convert.py +0 -0
  125. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/style_constants.py +0 -0
  126. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/unify_name.py +0 -0
  127. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/utils/xpath_query.py +0 -0
  128. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/variable.py +0 -0
  129. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/variable_declaration.py +0 -0
  130. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/version.py +0 -0
  131. {odfdo-3.26.3 → odfdo-3.27.2}/src/odfdo/xmlpart.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: odfdo
3
- Version: 3.26.3
3
+ Version: 3.27.2
4
4
  Summary: Python library for OpenDocument Format
5
5
  Keywords: python,library,ODF,OpenDocument
6
6
  Author: Jérôme Dumonteil
@@ -96,7 +96,7 @@ uv run python doc_src/generate_doc.py
96
96
 
97
97
  # Dependencies
98
98
 
99
- The project is tested on Python 3.10 to 3.14 (Linux, Mac, Windows). See previous releases for earlier versions of Python. For Python 3.9, see branch `support/python39`.
99
+ The project is tested on Python 3.10 to 3.15 (Linux, Mac, Windows). See previous releases for earlier versions of Python. For Python 3.9, see branch `support/python39`.
100
100
 
101
101
  A special effort has been made to limit the dependencies of this library: the only (non-development) dependency is `lxml`. The required versions of `lxml` depend mainly on the version of Python used; see the `pyproject.toml` file for details. The project tries to keep up with `lxml` version updates regularly.
102
102
 
@@ -107,7 +107,7 @@ A special effort has been made to limit the dependencies of this library: the on
107
107
  ```python
108
108
  from odfdo import Document, Paragraph
109
109
 
110
- doc = Document('text')
110
+ doc = Document("text")
111
111
  doc.body.append(Paragraph("Hello world!"))
112
112
 
113
113
  doc.save("hello.odt")
@@ -118,13 +118,13 @@ doc.save("hello.odt")
118
118
  ```python
119
119
  from odfdo import Document
120
120
 
121
- doc = Document('existing_spreadsheet.ods')
121
+ doc = Document("existing_spreadsheet.ods")
122
122
  sheet = doc.body.get_sheet(0)
123
123
 
124
124
  print(f"Value of A1: {sheet.get_cell('A1').value}")
125
- sheet.set_value('B2', 'Updated Value')
125
+ sheet.set_value("B2", "Updated Value")
126
126
 
127
- doc.save('modified_spreadsheet.ods')
127
+ doc.save("modified_spreadsheet.ods")
128
128
  ```
129
129
 
130
130
  ## Utilities
@@ -63,7 +63,7 @@ uv run python doc_src/generate_doc.py
63
63
 
64
64
  # Dependencies
65
65
 
66
- The project is tested on Python 3.10 to 3.14 (Linux, Mac, Windows). See previous releases for earlier versions of Python. For Python 3.9, see branch `support/python39`.
66
+ The project is tested on Python 3.10 to 3.15 (Linux, Mac, Windows). See previous releases for earlier versions of Python. For Python 3.9, see branch `support/python39`.
67
67
 
68
68
  A special effort has been made to limit the dependencies of this library: the only (non-development) dependency is `lxml`. The required versions of `lxml` depend mainly on the version of Python used; see the `pyproject.toml` file for details. The project tries to keep up with `lxml` version updates regularly.
69
69
 
@@ -74,7 +74,7 @@ A special effort has been made to limit the dependencies of this library: the on
74
74
  ```python
75
75
  from odfdo import Document, Paragraph
76
76
 
77
- doc = Document('text')
77
+ doc = Document("text")
78
78
  doc.body.append(Paragraph("Hello world!"))
79
79
 
80
80
  doc.save("hello.odt")
@@ -85,13 +85,13 @@ doc.save("hello.odt")
85
85
  ```python
86
86
  from odfdo import Document
87
87
 
88
- doc = Document('existing_spreadsheet.ods')
88
+ doc = Document("existing_spreadsheet.ods")
89
89
  sheet = doc.body.get_sheet(0)
90
90
 
91
91
  print(f"Value of A1: {sheet.get_cell('A1').value}")
92
- sheet.set_value('B2', 'Updated Value')
92
+ sheet.set_value("B2", "Updated Value")
93
93
 
94
- doc.save('modified_spreadsheet.ods')
94
+ doc.save("modified_spreadsheet.ods")
95
95
  ```
96
96
 
97
97
  ## Utilities
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "odfdo"
3
- version = "3.26.3"
3
+ version = "3.27.2"
4
4
  description = "Python library for OpenDocument Format"
5
5
  license = "Apache-2.0"
6
6
  license-files = [
@@ -76,21 +76,21 @@ doc = [
76
76
  ]
77
77
  dev = [
78
78
  "duckdb>=1.0.0",
79
- "iniconfig>=2.1.0",
79
+ "iniconfig>=2.3.1",
80
80
  "numpy>=1.24.0",
81
81
  "openpyxl>=3.1.0",
82
82
  "pandas>=2.0.0",
83
83
  "pillow>=12.1.1",
84
84
  "polars>=1.0.0",
85
85
  "pyexcel>=0.7.0",
86
- "pytest>=8.4.2",
86
+ "pytest>=9.1.1",
87
87
  "pytest-xdist>=3.8.0",
88
88
  "coverage>=7.16.1",
89
89
  "pytest-cov>=7.0.0",
90
90
  "tabulate>=0.9.0",
91
- "tox>=4.64.3",
92
- "ruff>=0.16.9",
93
- "ty>=0.0.84",
91
+ "tox>=4.63.0",
92
+ "ruff>=0.17.0",
93
+ "ty>=0.0.89",
94
94
  ]
95
95
 
96
96
  [tool.uv]
@@ -216,7 +216,7 @@ ignore = [
216
216
  "recipes/accessing_a_single_element.py" = ["RUF001"]
217
217
 
218
218
  [tool.pytest.ini_options]
219
- minversion = "8.0"
219
+ minversion = "9.0"
220
220
  testpaths = ["tests"]
221
221
 
222
222
  [tool.coverage.run]
@@ -247,5 +247,5 @@ close-quotes-on-newline = true
247
247
  non-strict = true
248
248
 
249
249
  [build-system]
250
- requires = ["uv_build>=0.9.0,<0.13.0"]
250
+ requires = ["uv_build>=0.12.0,<0.14.0"]
251
251
  build-backend = "uv_build"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "odfdo"
3
- version = "3.26.3"
3
+ version = "3.27.2"
4
4
  description = "Python library for OpenDocument Format"
5
5
  license = "Apache-2.0"
6
6
  license-files = ["LICENSE", "NOTICE.txt"]
@@ -65,21 +65,21 @@ doc = [
65
65
  ]
66
66
  dev = [
67
67
  "duckdb>=1.0.0", # for recipes about duckdb
68
- "iniconfig>=2.1.0",
68
+ "iniconfig>=2.3.1",
69
69
  "numpy>=1.24.0", # for recipes about numpy
70
70
  "openpyxl>=3.1.0", # for recipes about openpyxl
71
71
  "pandas>=2.0.0", # for recipes about pandas
72
72
  "pillow>=12.1.1",
73
73
  "polars>=1.0.0", # for recipes about polars
74
74
  "pyexcel>=0.7.0", # for recipes about pyexcel
75
- "pytest>=8.4.2",
75
+ "pytest>=9.1.1",
76
76
  "pytest-xdist>=3.8.0",
77
77
  "coverage>=7.16.1",
78
78
  "pytest-cov>=7.0.0",
79
79
  "tabulate>=0.9.0", # for recipes about tabulate
80
- "tox>=4.64.3",
81
- "ruff>=0.16.9",
82
- "ty>=0.0.84",
80
+ "tox>=4.63.0",
81
+ "ruff>=0.17.0",
82
+ "ty>=0.0.89",
83
83
  ]
84
84
 
85
85
  [tool.uv]
@@ -89,7 +89,7 @@ default-groups = ["doc", "dev"]
89
89
  source-exclude = [".DS_Store"]
90
90
 
91
91
  [build-system]
92
- requires = ["uv_build>=0.9.0,<0.13.0"]
92
+ requires = ["uv_build>=0.12.0,<0.14.0"]
93
93
  build-backend = "uv_build"
94
94
 
95
95
  [tool.ty.environment]
@@ -207,7 +207,7 @@ ignore = [
207
207
  "recipes/accessing_a_single_element.py" = ["RUF001"]
208
208
 
209
209
  [tool.pytest.ini_options]
210
- minversion = "8.0"
210
+ minversion = "9.0"
211
211
  testpaths = ["tests"]
212
212
 
213
213
  [tool.coverage.run]
@@ -1376,6 +1376,25 @@ class Document(MDDocument):
1376
1376
  root_entry.set_attribute("manifest:version", OFFICE_VERSION)
1377
1377
  self.container.set_part(ODF_MANIFEST, manifest.serialize())
1378
1378
 
1379
+ def normalize_tables(self) -> None:
1380
+ """Ensure all tables in the document have table:table-column
1381
+ definitions covering the full width of their rows.
1382
+ """
1383
+ if not self.container:
1384
+ return
1385
+ tables: list[Table] = []
1386
+ with contextlib.suppress(ValueError, AttributeError, TypeError):
1387
+ tables.extend(self.body.get_tables())
1388
+ styles = self.get_part(ODF_STYLES)
1389
+ if isinstance(styles, XmlPart):
1390
+ tables.extend(
1391
+ elem
1392
+ for elem in styles.get_elements("//table:table")
1393
+ if isinstance(elem, Table)
1394
+ )
1395
+ for table in tables:
1396
+ table.normalize_columns()
1397
+
1379
1398
  def save(
1380
1399
  self,
1381
1400
  target: str | Path | io.BytesIO | None = None,
@@ -1427,11 +1446,12 @@ class Document(MDDocument):
1427
1446
  pretty = bool(pretty)
1428
1447
  backup = bool(backup)
1429
1448
  # Folder packaging is intended for debugging/analysis: preserve the
1430
- # original parts (version, missing files, manifest.rdf) as much as
1431
- # possible, but still pretty-print XML when requested.
1449
+ # original parts (version, missing files, manifest.rdf, table columns)
1450
+ # as much as possible, but still pretty-print XML when requested.
1432
1451
  if packaging != FOLDER:
1433
1452
  self._ensure_odf14()
1434
1453
  self._check_manifest_rdf()
1454
+ self.normalize_tables()
1435
1455
  if pretty and packaging != XML:
1436
1456
  for path, part in self.__xmlparts.items():
1437
1457
  if part is not None:
@@ -640,8 +640,9 @@ class MDTable(MDStyle):
640
640
  ]
641
641
 
642
642
  table = self.clone
643
+ table.normalize_columns()
643
644
  table.rstrip(aggressive=True)
644
- if not table.height:
645
+ if not table.height or not table.width:
645
646
  return ""
646
647
  if table.height > MAX_MD_LINES:
647
648
  msg = f"Table row count {table.height} exceeds limit {MAX_MD_LINES}"
@@ -41,9 +41,7 @@ class OfficeFormsMixin(Element):
41
41
  OfficeForms | None: The `OfficeForms` instance if found, otherwise `None`.
42
42
 
43
43
  """
44
- return cast(
45
- "OfficeForms | None", self.get_element("descendant::office:forms")
46
- )
44
+ return cast("OfficeForms | None", self.get_element("descendant::office:forms"))
47
45
 
48
46
  @property
49
47
  def office_forms(self) -> OfficeForms | None:
@@ -30,7 +30,7 @@ from __future__ import annotations
30
30
  from argparse import ArgumentParser, Namespace
31
31
  from pathlib import Path
32
32
 
33
- from odfdo import Document, __version__
33
+ from odfdo import Container, Document, __version__
34
34
  from odfdo.const import FOLDER, ZIP
35
35
 
36
36
  PROG = "odfdo-folder"
@@ -85,21 +85,23 @@ def main_convert_folder(args: Namespace) -> None:
85
85
 
86
86
 
87
87
  def convert_folder(path_str: str) -> None:
88
- """Convert the specified file or folder to/from folder packaging."""
88
+ """Convert the specified file or folder to/from folder packaging.
89
+
90
+ Folder packaging skips version upgrades, missing-part creation,
91
+ generator updates, and table columns normalization, but pretty-print
92
+ modified parts to ease debugging.
93
+ """
89
94
  path = Path(path_str)
90
- pretty = False
91
95
  if path.is_file():
92
- out_packaging = FOLDER
93
- pretty = True
96
+ document = Document(path)
97
+ document.save(packaging=FOLDER, pretty=True)
94
98
  elif path.is_dir():
95
- out_packaging = ZIP
99
+ container = Container()
100
+ container.open(path)
101
+ container.save(None, packaging=ZIP)
96
102
  else:
97
103
  msg = f"Not a file or folder: {path!r}"
98
104
  raise ValueError(msg)
99
- document = Document(path)
100
- # Folder packaging skips version upgrades, missing-part creation and
101
- # generator updates, but pretty-print modified parts to ease debugging.
102
- document.save(packaging=out_packaging, pretty=pretty)
103
105
 
104
106
 
105
107
  if __name__ == "__main__":
@@ -500,15 +500,36 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
500
500
  _XP_COLUMN, "table:number-columns-repeated"
501
501
  )
502
502
  self._table_cache.make_col_map(idx_repeated_seq)
503
+ if self._table_cache.col_map_length() == 0 and self._table_cache.height() > 0:
504
+ self.normalize_columns()
503
505
 
504
506
  def _update_width(self, row: Row) -> None:
505
507
  """Synchronize the number of columns if the row is bigger.
506
508
 
507
509
  Append, don't insert, not to disturb the current layout.
508
510
  """
509
- diff = row.width - self.width
511
+ diff = row.width - self._table_cache.width()
510
512
  if diff > 0:
511
513
  self.append_column(Column(repeated=diff))
514
+ self._table_cache.cached_width = None
515
+
516
+ def normalize_columns(self) -> None:
517
+ """Ensure that table:table-column definitions cover the full width of
518
+ the rows.
519
+
520
+ If the table lacks table:table-column elements or if the existing
521
+ columns do not cover the maximum width of the rows, default column
522
+ definitions are appended to match the maximum row width.
523
+ """
524
+ rows = self._get_rows()
525
+ if not rows:
526
+ return
527
+ max_row_width = max((row.width for row in rows), default=0)
528
+ col_width = self._table_cache.width()
529
+ diff = max_row_width - col_width
530
+ if diff > 0:
531
+ self.append_column(Column(repeated=diff))
532
+ self._table_cache.cached_width = None
512
533
 
513
534
  def _get_formatted_text_normal(self, context: dict | None) -> str:
514
535
  result = []
@@ -691,7 +712,7 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
691
712
  @property
692
713
  def width(self) -> int:
693
714
  """Get the current width of the table, based on the column
694
- definitions.
715
+ definitions and row contents.
695
716
 
696
717
  Note that individual rows may have different widths. It is recommended
697
718
  to use the Table API to maintain a consistent width.
@@ -700,8 +721,21 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
700
721
  int: The number of columns in the table.
701
722
 
702
723
  """
703
- # Columns are our reference for user expected width
704
- return self._table_cache.width()
724
+ cached = self._table_cache.cached_width
725
+ if cached is not None:
726
+ return cached
727
+ # known columns width
728
+ col_width = self._table_cache.width()
729
+ if self._table_cache.height() == 0:
730
+ self._table_cache.cached_width = col_width
731
+ return col_width
732
+ # secure computation (do not trust table-column computation)
733
+ rows = self._get_rows()
734
+ max_row_width = max(
735
+ col_width, max((row.width for row in rows), default=col_width)
736
+ )
737
+ self._table_cache.cached_width = max_row_width
738
+ return max_row_width
705
739
 
706
740
  @property
707
741
  def size(self) -> tuple[int, int]:
@@ -1258,6 +1292,8 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
1258
1292
  some cells may be overwritten.
1259
1293
 
1260
1294
  """
1295
+ if self.width == 0 or self.height == 0:
1296
+ return
1261
1297
  data = []
1262
1298
  if coord is None:
1263
1299
  data = [row.cells for row in self.iter_rows()]
@@ -1560,13 +1596,7 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
1560
1596
  self.extend(rows)
1561
1597
  self._compute_table_cache()
1562
1598
  # Update width if necessary
1563
- width = self.width
1564
- for row in self.iter_rows():
1565
- if row.width > width:
1566
- width = row.width
1567
- diff = width - self.width
1568
- if diff > 0:
1569
- self.append_column(Column(repeated=diff))
1599
+ self.normalize_columns()
1570
1600
 
1571
1601
  def append_row(
1572
1602
  self,
@@ -2245,6 +2275,13 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2245
2275
  return
2246
2276
  column.x = x
2247
2277
  yield column
2278
+ while x < min(end, self.width - 1):
2279
+ x += 1
2280
+ if x < start:
2281
+ continue
2282
+ col = Column()
2283
+ col.x = x
2284
+ yield col
2248
2285
 
2249
2286
  traverse_columns = iter_columns
2250
2287
 
@@ -2291,8 +2328,8 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2291
2328
  return columns
2292
2329
 
2293
2330
  def _get_column2(self, x: int) -> Column | None:
2294
- # Outside the defined table
2295
- if x >= self.width:
2331
+ # Outside the XML-defined columns ?
2332
+ if x >= self._table_cache.width():
2296
2333
  return Column()
2297
2334
  idx = self._table_cache.col_idx(x)
2298
2335
  if idx is None:
@@ -2366,8 +2403,8 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2366
2403
  else:
2367
2404
  repeated = column.repeated or 1
2368
2405
  column.x = x
2369
- # Outside the defined table ?
2370
- diff = x - self.width
2406
+ col_width = self._table_cache.width()
2407
+ diff = x - col_width
2371
2408
  if diff == 0:
2372
2409
  column_back = self.append_column(column, _repeated=repeated)
2373
2410
  elif diff > 0:
@@ -2376,6 +2413,7 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2376
2413
  else:
2377
2414
  # Inside the defined table
2378
2415
  column_back = self._table_cache.set_col_in_cache(x, column, self)
2416
+ self._table_cache.clear_col_indexes()
2379
2417
  return column_back
2380
2418
 
2381
2419
  def insert_column(
@@ -2398,7 +2436,8 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2398
2436
  if column is None:
2399
2437
  column = Column()
2400
2438
  x = self._translate_x_from_any(x)
2401
- diff = x - self.width
2439
+ col_width = self._table_cache.width()
2440
+ diff = x - col_width
2402
2441
  if diff < 0:
2403
2442
  column_back = self._table_cache.insert_col_in_cache(x, column, self)
2404
2443
  elif diff == 0:
@@ -2415,6 +2454,8 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2415
2454
  row.insert_cell(x, Cell(repeated=repeated))
2416
2455
  # Shorter rows don't need insert
2417
2456
  # Longer rows shouldn't exist!
2457
+ self._table_cache.clear_row_indexes()
2458
+ self._table_cache.clear_col_indexes()
2418
2459
  return column_back
2419
2460
 
2420
2461
  def append_column(
@@ -2432,8 +2473,7 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2432
2473
  _repeated: The number of times the column is repeated.
2433
2474
 
2434
2475
  Returns:
2435
- Column: The newly appended column, with its `x` attribute
2436
- updated.
2476
+ Column: The newly appended column, with its `x` attribute updated.
2437
2477
 
2438
2478
  """
2439
2479
  if column is None:
@@ -2444,17 +2484,27 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2444
2484
  odf_idx = self._table_cache.col_map_length() - 1
2445
2485
  if odf_idx < 0:
2446
2486
  position = 0
2487
+ for idx, child in enumerate(self.children):
2488
+ if child.tag in (
2489
+ "table:table-row",
2490
+ "table:table-row-group",
2491
+ "table:table-header-rows",
2492
+ "table:table-rows",
2493
+ ):
2494
+ position = idx
2495
+ break
2447
2496
  else:
2448
2497
  last_column = self._get_element_idx2(_XP_COLUMN_IDX, odf_idx)
2449
2498
  if last_column is None:
2450
2499
  raise ValueError
2451
2500
  position = self.index(last_column) + 1
2452
- column.x = self.width
2501
+ column.x = self._table_cache.width()
2453
2502
  self.insert(column, position=position)
2454
2503
  # Repetitions are accepted
2455
2504
  if _repeated is None:
2456
2505
  _repeated = column.repeated or 1
2457
2506
  self._table_cache.insert_col_map_once(_repeated)
2507
+ self._table_cache.clear_col_indexes()
2458
2508
  # No need to update row widths
2459
2509
  return column
2460
2510
 
@@ -2471,12 +2521,15 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
2471
2521
  if x >= self.width:
2472
2522
  return
2473
2523
  # Inside the defined table
2474
- self._table_cache.delete_col_in_cache(x, self)
2524
+ col_width = self._table_cache.width()
2525
+ if x < col_width:
2526
+ self._table_cache.delete_col_in_cache(x, self)
2475
2527
  # Update width
2476
- width = self.width
2477
2528
  for row in self._get_rows():
2478
- if row.width >= width:
2529
+ if row.width > x:
2479
2530
  row.delete_cell(x)
2531
+ self._table_cache.clear_row_indexes()
2532
+ self._table_cache.clear_col_indexes()
2480
2533
 
2481
2534
  def get_column_cells(
2482
2535
  self,
@@ -3077,7 +3130,7 @@ class Table(MDTable, FormMixin, OfficeFormsMixin, Element):
3077
3130
  return (cloned_table.height, cloned_table.width)
3078
3131
 
3079
3132
  @property
3080
- def headers(self) -> list[CellValue | None]:
3133
+ def headers(self) -> list[CellValue | None]: # ty: ignore[invalid-property-type-override]
3081
3134
  """Return the first row of table values (column headers) after rstrip.
3082
3135
 
3083
3136
  The table remains unchanged.
@@ -410,7 +410,13 @@ class RowCache:
410
410
  class TableCache:
411
411
  """Cache for Table (internal)."""
412
412
 
413
- __slots__ = ("col_elements", "col_map", "row_elements", "row_map")
413
+ __slots__ = (
414
+ "cached_width",
415
+ "col_elements",
416
+ "col_map",
417
+ "row_elements",
418
+ "row_map",
419
+ )
414
420
 
415
421
  def __init__(self) -> None:
416
422
  """Initialize a TableCache."""
@@ -418,6 +424,7 @@ class TableCache:
418
424
  self.col_map: list[int] = []
419
425
  self.row_elements: dict[int, Row] = {}
420
426
  self.col_elements: dict[int, Column] = {}
427
+ self.cached_width: int | None = None
421
428
 
422
429
  def __str__(self) -> str:
423
430
  return f"TC row:{self.row_map!r} col:{self.col_map!r}"
@@ -428,6 +435,7 @@ class TableCache:
428
435
  tc = cls()
429
436
  tc.row_map = source.row_map[:]
430
437
  tc.col_map = source.col_map[:]
438
+ tc.cached_width = source.cached_width
431
439
  return tc
432
440
 
433
441
  def height(self) -> int:
@@ -460,10 +468,12 @@ class TableCache:
460
468
  def clear_row_indexes(self) -> None:
461
469
  """Clear the indexed cached rows."""
462
470
  self.row_elements = {}
471
+ self.cached_width = None
463
472
 
464
473
  def clear_col_indexes(self) -> None:
465
474
  """Clear the indexed cached columns."""
466
475
  self.col_elements = {}
476
+ self.cached_width = None
467
477
 
468
478
  def row_idx(self, position: int) -> int | None:
469
479
  """Find row index in the map from the position."""
@@ -502,6 +512,7 @@ class TableCache:
502
512
  def insert_row_map_once(self, repeated: int) -> None:
503
513
  """Insert a repeated row count into the row map."""
504
514
  self.row_map = _insert_map_once(self.row_map, len(self.row_map), repeated)
515
+ self.cached_width = None
505
516
 
506
517
  # def erase_row_map_once(self, odf_idx: int) -> None:
507
518
  # self.row_map = _erase_map_once(self.row_map, odf_idx)
@@ -509,6 +520,7 @@ class TableCache:
509
520
  def insert_col_map_once(self, repeated: int) -> None:
510
521
  """Insert a repeated column count into the column map."""
511
522
  self.col_map = _insert_map_once(self.col_map, len(self.col_map), repeated)
523
+ self.cached_width = None
512
524
 
513
525
  # def erase_col_map_once(self, odf_idx: int) -> None:
514
526
  # self.col_map = _erase_map_once(self.col_map, odf_idx)
@@ -516,10 +528,12 @@ class TableCache:
516
528
  def make_row_map(self, idx_repeated_sequence: list[tuple[int, int]]) -> None:
517
529
  """Build the row map from repeated sequence data."""
518
530
  self.row_map = _make_cache_map(idx_repeated_sequence)
531
+ self.cached_width = None
519
532
 
520
533
  def make_col_map(self, idx_repeated_sequence: list[tuple[int, int]]) -> None:
521
534
  """Build the column map from repeated sequence data."""
522
535
  self.col_map = _make_cache_map(idx_repeated_sequence)
536
+ self.cached_width = None
523
537
 
524
538
  def set_row_in_cache(
525
539
  self,