[GH-ISSUE #356] text Wrap issues on different platforms #283

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

Originally created by @LLMIKU on GitHub (Sep 15, 2021).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/356

Using 1.1.3 now.

Here is the problem:

If you wish to control where the text is wrapped you can add newline characters to the string:

format = workbook_add_format(workbook);
format_set_text_wrap(format);
 
worksheet_write_string(worksheet, 0, 0, "It's\na bum\nwrap", format);

When I open this file with Numbers on Mac, it shows text is wrapped.
However, when I open it on Windows(Excel) or Android(Latest version WPS),it shows text is not wrapped, but when I edit it, I can see the \n effect.

Maybe something goes wrong in lxw_escape_control_characters(string) function, but I am not familiar with xlsx format. Is "_x%04X_" this a format control sign?

Originally created by @LLMIKU on GitHub (Sep 15, 2021). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/356 Using 1.1.3 now. Here is the problem: > If you wish to control where the text is wrapped you can add newline characters to the string: ``` format = workbook_add_format(workbook); format_set_text_wrap(format); worksheet_write_string(worksheet, 0, 0, "It's\na bum\nwrap", format); ``` When I open this file with Numbers on Mac, it shows text is wrapped. However, when I open it on Windows(Excel) or Android(Latest version WPS),it shows text is not wrapped, but when I edit it, I can see the \n effect. Maybe something goes wrong in `lxw_escape_control_characters(string)` function, but I am not familiar with xlsx format. Is **"\_x%04X\_"** this a format control sign?
gitea-mirror 2026-05-05 12:05:59 -06:00
Author
Owner

@jmcnamara commented on GitHub (Sep 15, 2021):

However, when I open it on Windows(Excel) ... it shows text is not wrapped

It should work as expected in all versions of Excel. Here is an example program:

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("test.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    lxw_format *format = workbook_add_format(workbook);
    format_set_text_wrap(format);
 
    worksheet_write_string(worksheet, 0, 0, "It's\na bum\nwrap", format);

    
    workbook_close(workbook);

    return 0;
}

Output:

screenshot

As you can see the test is wrapped as expected.

It may appear differently in other applications but that isn't usually an issue with libxlsxwriter since it follows Excel's format exactly.

One thing to note is that Excel automatically expands the height of the row when the file is opened. This isn't something that is controllable by the file format, it is something that happens at run time when Excel opens the file. So if you don't see that in other applications you may have to specify the row height explicitly.

Anyway, can you test the code above with Excel and confirm you get the same results, or otherwise.

<!-- gh-comment-id:920195330 --> @jmcnamara commented on GitHub (Sep 15, 2021): > However, when I open it on Windows(Excel) ... it shows text is not wrapped It should work as expected in all versions of Excel. Here is an example program: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("test.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_format *format = workbook_add_format(workbook); format_set_text_wrap(format); worksheet_write_string(worksheet, 0, 0, "It's\na bum\nwrap", format); workbook_close(workbook); return 0; } ``` Output: ![screenshot](https://user-images.githubusercontent.com/94267/133475633-718e3e1d-5b5c-4856-abdb-fe1fe569d80e.png) As you can see the test is wrapped as expected. It may appear differently in other applications but that isn't usually an issue with libxlsxwriter since it follows Excel's format exactly. One thing to note is that Excel automatically expands the height of the row when the file is opened. This isn't something that is controllable by the file format, it is something that happens at run time when Excel opens the file. So if you don't see that in other applications you may have to specify the row height explicitly. Anyway, can you test the code above with Excel and confirm you get the same results, or otherwise.
Author
Owner

@LLMIKU commented on GitHub (Sep 15, 2021):

Thanks a lot, I haven't add that format_set_text_wrap(format);, after added, it works perfect!

<!-- gh-comment-id:920206350 --> @LLMIKU commented on GitHub (Sep 15, 2021): Thanks a lot, I haven't add that `format_set_text_wrap(format);`, after added, it works perfect!
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#283
No description provided.