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

Comment size varies depending on intervening rows and columns #403

Closed
jkyeung opened this issue Dec 23, 2016 · 6 comments

Comments

Projects
None yet
2 participants
@jkyeung
Copy link
Contributor

commented Dec 23, 2016

Using Python 2.7, XlsxWriter 0.9.4, and Excel 2010.

This seems at least superficially related to #45:

from xlsxwriter import Workbook

comment_text = 'These comments should be identically sized.'
comment_options = {'width': 200, 'height': 30, 'visible': True}

with Workbook('comment_test.xlsx') as wb:
    ws = wb.add_worksheet()
    ws.write_comment('B3', comment_text, comment_options)
    ws.write_comment('B6', comment_text, comment_options)
    ws.write_comment('G3', comment_text, comment_options)
    ws.write_comment('G6', comment_text, comment_options)
    ws.set_column('D:D', 5)
    ws.set_column('I:I', 20)
    ws.set_row(5, 40)

The above code produces

comment_test

Obviously, it would be ideal if all four of those comments were the same size. But I would not be surprised if the Excel format makes those calculations difficult.

@jkyeung

This comment has been minimized.

Copy link
Contributor Author

commented Dec 23, 2016

OK, I think I see that this would be extremely difficult to "fix". If the size of the rows and columns is changed before the comment is written, XlsxWriter can take those into account. But once the comment is written (at the time that write_comment is called), the corners of the bounding box are "pinned" to specific positions within cells. The only way to remedy this would seem to be somehow deferring the comment box calculations until close time.

@jmcnamara

This comment has been minimized.

Copy link
Owner

commented Dec 24, 2016

The only way to remedy this would seem to be somehow deferring the comment box calculations until close time.

I think that it is just a historical oversight that it isn't done like that. That is the default behaviour for charts, images and other objects.

I'll look into fixing it so that it behaves as expected.

Thanks.

@jmcnamara jmcnamara self-assigned this Dec 24, 2016

@jmcnamara

This comment has been minimized.

Copy link
Owner

commented Aug 17, 2018

This is a similar or related issue to #312. I'll merge them into one and fix them together.

@jmcnamara

This comment has been minimized.

Copy link
Owner

commented Apr 12, 2019

It took me a while to get around to looking at this issue you reported in XlsxWriter.

The code will actually work as expected but only if you put the set_column() and set_row() calls before the calls to write_comment(), like this:

from xlsxwriter import Workbook

comment_text = 'These comments should be identically sized.'
comment_options = {'width': 200, 'height': 30, 'visible': True}

with Workbook('comment_test.xlsx') as wb:
    ws = wb.add_worksheet()

    ws.set_column('D:D', 5)
    ws.set_column('I:I', 20)
    ws.set_row(5, 40)

    ws.write_comment('B3', comment_text, comment_options)
    ws.write_comment('B6', comment_text, comment_options)
    ws.write_comment('G3', comment_text, comment_options)
    ws.write_comment('G6', comment_text, comment_options)

Output:
gh403

This issue doesn't happen for other objects in XlsxWriter such as images, charts and textboxes since their dimensions are calculated as the worksheet is closed (and all the row and column changes have been made). For some historical reason that I can't remember now, comments sizes are calculated at write time. I could fix this be treating them like other objects but I'm not sure it is worth the effort. I may just document it as expected behaviour for now.

@jmcnamara

This comment has been minimized.

Copy link
Owner

commented Apr 13, 2019

I'm not sure it is worth the effort. I may just document it as expected behaviour for now.

Changed my mind. It is probably easier to fix than to document.

@jmcnamara jmcnamara closed this in a0306f4 Apr 13, 2019

@jmcnamara

This comment has been minimized.

Copy link
Owner

commented Apr 13, 2019

Fixed on master. This change should go into version 1.1.7. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.