Skip to content

Commit e53e190

Browse files
committed
format: fix identation and alignment property mismatch
Fix issue where a horizontal alignment format was ignored if the indentation was also set. Issue: #1041
1 parent 53d5086 commit e53e190

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

Changes

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2+
3+
4+
Release 3.2.0 - February XX 2023
5+
--------------------------------
6+
7+
* Fix issue where a horizontal alignment format was ignored if indentation was
8+
also set.
9+
10+
:issue:`1041`.
11+
12+
113
Release 3.1.9 - October 19 2023
214
-------------------------------
315

xlsxwriter/format.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,17 @@ def _get_align_properties(self):
784784
else:
785785
return changed, align
786786

787-
# Indent is only allowed for horizontal left, right and distributed.
788-
# If it is defined for any other alignment or no alignment has
789-
# been set then default to left alignment.
787+
# Indent is only allowed for some alignment properties. If it is
788+
# defined for any other alignment or no alignment has been set then
789+
# default to left alignment.
790790
if (
791791
self.indent
792792
and self.text_h_align != 1
793793
and self.text_h_align != 3
794794
and self.text_h_align != 7
795+
and self.text_v_align != 1
796+
and self.text_v_align != 3
797+
and self.text_v_align != 5
795798
):
796799
self.text_h_align = 1
797800

@@ -840,10 +843,10 @@ def _get_align_properties(self):
840843
if self.text_v_align == 5:
841844
align.append(("vertical", "distributed"))
842845

843-
if self.indent:
844-
align.append(("indent", self.indent))
845846
if self.rotation:
846847
align.append(("textRotation", self.rotation))
848+
if self.indent:
849+
align.append(("indent", self.indent))
847850

848851
if self.text_wrap:
849852
align.append(("wrapText", 1))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
###############################################################################
2+
#
3+
# Tests for XlsxWriter.
4+
#
5+
# SPDX-License-Identifier: BSD-2-Clause
6+
# Copyright (c), 2013-2024, John McNamara, [email protected]
7+
#
8+
9+
from ..excel_comparison_test import ExcelComparisonTest
10+
from ...workbook import Workbook
11+
12+
13+
class TestCompareXLSXFiles(ExcelComparisonTest):
14+
"""
15+
Test file created by XlsxWriter against a file created by Excel.
16+
17+
"""
18+
19+
def setUp(self):
20+
self.set_filename("format24.xlsx")
21+
22+
def test_create_file(self):
23+
"""Test the creation of a simple XlsxWriter file with automatic color."""
24+
25+
workbook = Workbook(self.got_filename)
26+
27+
worksheet = workbook.add_worksheet()
28+
29+
format1 = workbook.add_format(
30+
{"rotation": 270, "indent": 1, "align": "center", "valign": "top"}
31+
)
32+
33+
worksheet.set_row(0, 75)
34+
35+
worksheet.write(0, 0, "ABCD", format1)
36+
37+
workbook.close()
38+
39+
self.assertExcelEqual()
Binary file not shown.

0 commit comments

Comments
 (0)