Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Text in textboxes not aligning correctly #684

Closed
omkhamsa opened this issue Jan 28, 2020 · 2 comments
Closed

Issue with Text in textboxes not aligning correctly #684

omkhamsa opened this issue Jan 28, 2020 · 2 comments
Assignees
Labels
feature request medium term Probably will be added.

Comments

@omkhamsa
Copy link

Hi,

When I insert text that wraps around multiple lines and set the alignment in options to center it instead aligns to the left

I'm using Python 3.7 and XlsxWriter 1.2.7 and Excel 2019. The issue appears on google sheets too.

Here is some code that demonstrates the problem:

import xlsxwriter

wb = xlsxwriter.Workbook('test.xlsx')
ws = wb.add_worksheet()

text = 'This is a very long text that should wrap around multiple line and still be in the center'
options = {
    'align': {'vertical': 'middle',
               'horizontal': 'center'},
}
ws.insert_textbox(0,0, text, options)

wb.close()
@jmcnamara jmcnamara self-assigned this Jan 28, 2020
@jmcnamara jmcnamara added the under investigation The issue is being investigated. label Jan 28, 2020
@jmcnamara
Copy link
Owner

Thanks for the report.

This is a little odd since I have a test case with almost exactly this configuration: https://github.com/jmcnamara/XlsxWriter/blob/master/xlsxwriter/test/comparison/test_textbox18.py

Also, the text is centered, in a way. For example if you make the textbox much wider you can see that the text is in the center:

import xlsxwriter

wb = xlsxwriter.Workbook('test.xlsx')
ws = wb.add_worksheet()

text = 'This is a very long text that should wrap around multiple line and still be in the center'
options = {
    'width': 640,   
    'align': {'vertical': 'middle',
               'horizontal': 'center'},
}
ws.insert_textbox(0, 0, text, options)

wb.close()

Nevertheless, I can see that it isn't rendered as you would expect. There is another center that needs to be applied to the text itself.

I'll look into.

@jmcnamara jmcnamara added feature request medium term Probably will be added. and removed under investigation The issue is being investigated. labels Sep 19, 2020
jmcnamara added a commit that referenced this issue Sep 26, 2020
Added text alignment for textboxes. The existing options allowed
the text area to be aligned but didn't offer control over the
text within that area.

Issue #684
@jmcnamara
Copy link
Owner

Fixed on main. You can now specify a additional text alignment property to get the alignment you are looking for.

Like this:

import xlsxwriter

wb = xlsxwriter.Workbook('test.xlsx')
ws = wb.add_worksheet()

text = 'This is a long text line that should wrap around multiple lines and still be in the center'
options = {
    'align': {'vertical': 'middle',
               'horizontal': 'center',
               'text': 'center'},
}
ws.insert_textbox(0, 0, text, options)

wb.close()

Output:

screenshot

Thanks for the report. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request medium term Probably will be added.
Projects
None yet
Development

No branches or pull requests

2 participants