[GH-ISSUE #492] format_set_text_wrap has no effect on merged cells #383

Closed
opened 2026-05-05 12:14:05 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @znakeeye on GitHub (Oct 20, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/492

Using libxlsxwriter 1.1.9. See sample below. When merging the cells, the text wrapping does not work. Is this expected behavior? Is there a workaround?

Image
#include "xlsxwriter.h"

int main()
{
    lxw_workbook_options options = { 0 };
    lxw_workbook* wb = workbook_new_opt("foo.xlsx", &options);
    lxw_worksheet* ws = workbook_add_worksheet(wb, "Sheet1");

    lxw_format* format = workbook_add_format(wb);
    format_set_text_wrap(format);

    worksheet_write_string(ws, 0, 0, "Trying out multiple lines\nwith auto-sizing...\nThis works!", format);

    worksheet_merge_range(ws, 2, 0, 2, 2, "When merging...\nwrapping doesn't work though.\nExpected? :(", format);
    
    workbook_close(wb);

    return 0;
}
Originally created by @znakeeye on GitHub (Oct 20, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/492 Using `libxlsxwriter 1.1.9`. See sample below. When merging the cells, the text wrapping does not work. Is this expected behavior? Is there a workaround? <img width="244" height="300" alt="Image" src="https://github.com/user-attachments/assets/ac4b5ee8-987f-4b0e-904f-a2af895e1749" /> ```c #include "xlsxwriter.h" int main() { lxw_workbook_options options = { 0 }; lxw_workbook* wb = workbook_new_opt("foo.xlsx", &options); lxw_worksheet* ws = workbook_add_worksheet(wb, "Sheet1"); lxw_format* format = workbook_add_format(wb); format_set_text_wrap(format); worksheet_write_string(ws, 0, 0, "Trying out multiple lines\nwith auto-sizing...\nThis works!", format); worksheet_merge_range(ws, 2, 0, 2, 2, "When merging...\nwrapping doesn't work though.\nExpected? :(", format); workbook_close(wb); return 0; } ```
Author
Owner

@jmcnamara commented on GitHub (Oct 20, 2025):

I am away from a computer atm but I'm going to guess that text wrap does work in a merged range because that is something that I've tested and I'm pretty sure there is an example in the examples directory that uses it. Is that the case? If you manually change the height is the text wrapped?

I'm also going to guess that what you are actually reporting is that the row height isn't automatically adjusted when there is a merged range that has a text wrap. If that is the case then that is the expected behavior.

The automatic height adjustment is done by Excel at runtime and can't be triggered from the file format. I'd suggest setting an explicit height for the merged cells.

<!-- gh-comment-id:3421099010 --> @jmcnamara commented on GitHub (Oct 20, 2025): I am away from a computer atm but I'm going to guess that text wrap does work in a merged range because that is something that I've tested and I'm pretty sure there is an example in the examples directory that uses it. Is that the case? If you manually change the height is the text wrapped? I'm also going to guess that what you are actually reporting is that the row height isn't automatically adjusted when there is a merged range that has a text wrap. If that is the case then that is the expected behavior. The automatic height adjustment is done by Excel at runtime and can't be triggered from the file format. I'd suggest setting an explicit height for the merged cells.
Author
Owner

@znakeeye commented on GitHub (Oct 20, 2025):

Yes, manually changing the height works. Just verified the behavior in Excel. It seems it doesn't auto-adjust the height for merged cells.

Thanks for the suggested workaround!

<!-- gh-comment-id:3421915880 --> @znakeeye commented on GitHub (Oct 20, 2025): Yes, manually changing the height works. Just verified the behavior in Excel. It seems it doesn't auto-adjust the height for merged cells. Thanks for the suggested workaround!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#383
No description provided.