[GH-ISSUE #257] [Bug] Text Wrap in Outlook Preview mode #206

Closed
opened 2026-05-05 11:55:16 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @sirhvd on GitHub (Dec 20, 2019).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/257

Originally assigned to: @jmcnamara on GitHub.

Hi @jmcnamara.
I was using the excel files generated from libxlsxwriter library, and upload these file to Outlook mail. (https://outlook.office365.com/)

But I have a small problem when open Excel file in preview mode ( Outlook Mail ).
Text wrap not working in preview mode, but in Windows desktop, it's working fine.

To make text wrap work in preview mode, I must open the excel file then save it again.

I hope you will check it out.
Thank you
Cheers!

Originally created by @sirhvd on GitHub (Dec 20, 2019). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/257 Originally assigned to: @jmcnamara on GitHub. Hi @jmcnamara. I was using the excel files generated from **libxlsxwriter** library, and upload these file to Outlook mail. (https://outlook.office365.com/) But I have a small problem when open Excel file in preview mode ( Outlook Mail ). Text wrap not working in preview mode, but in Windows desktop, it's working fine. To make text wrap work in preview mode, I must open the excel file then save it again. I hope you will check it out. Thank you Cheers!
gitea-mirror 2026-05-05 11:55:16 -06:00
Author
Owner

@RaFaeL-NN commented on GitHub (Dec 20, 2019):

Excel saves files in text mode with \r\n. libxlsxwriter saves in binary mode. Excel can convert it "on the fly" at open, preview mode can't. See https://github.com/jmcnamara/libxlsxwriter/issues/156 . A solution can be with an option changing write mode (from binary to text).

<!-- gh-comment-id:567840774 --> @RaFaeL-NN commented on GitHub (Dec 20, 2019): Excel saves files in text mode with \r\n. libxlsxwriter saves in binary mode. Excel can convert it "on the fly" at open, preview mode can't. See https://github.com/jmcnamara/libxlsxwriter/issues/156 . A solution can be with an option changing write mode (from binary to text).
Author
Owner

@jmcnamara commented on GitHub (Dec 20, 2019):

@sirhvd could you add a small, complete C program that generates a file that demonstrates the issue.

Could you also, if possible add a screenshot of the preview in Outlook so that I can try replicate this.

<!-- gh-comment-id:567852432 --> @jmcnamara commented on GitHub (Dec 20, 2019): @sirhvd could you add a small, complete C program that generates a file that demonstrates the issue. Could you also, if possible add a screenshot of the preview in Outlook so that I can try replicate this.
Author
Owner

@sirhvd commented on GitHub (Dec 23, 2019):

@jmcnamara Sorry for the late reply. I just using your example code:

int main() {
    lxw_workbook  *workbook  = workbook_new("wrap.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    lxw_format *wrap_format = workbook_add_format(workbook);
    format_set_text_wrap(wrap_format);

    worksheet_write_string(worksheet, 0, 0, "Col 1", wrap_format);
    worksheet_write_string(worksheet, 0, 1, "Col 2", wrap_format);
    worksheet_write_string(worksheet, 1, 0, "First Long long long long long long text", wrap_format);
    worksheet_write_string(worksheet, 1, 1, "Second long long long long long long text", wrap_format);

    workbook_close(workbook);

    return 0;
}

Capture

I think this problem comes from text/binary mode as @RaFaeL-NN mentions.

<!-- gh-comment-id:568328258 --> @sirhvd commented on GitHub (Dec 23, 2019): @jmcnamara Sorry for the late reply. I just using your example code: ```C int main() { lxw_workbook *workbook = workbook_new("wrap.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_format *wrap_format = workbook_add_format(workbook); format_set_text_wrap(wrap_format); worksheet_write_string(worksheet, 0, 0, "Col 1", wrap_format); worksheet_write_string(worksheet, 0, 1, "Col 2", wrap_format); worksheet_write_string(worksheet, 1, 0, "First Long long long long long long text", wrap_format); worksheet_write_string(worksheet, 1, 1, "Second long long long long long long text", wrap_format); workbook_close(workbook); return 0; } ``` ![Capture](https://user-images.githubusercontent.com/8132142/71330918-19e9d900-2562-11ea-9321-25782f15ca8c.PNG) I think this problem comes from text/binary mode as @RaFaeL-NN mentions.
Author
Owner

@jmcnamara commented on GitHub (Dec 23, 2019):

Thanks for the sample code. I think I see what the issue may be.

When you set word wrap like this Excel resizes the row automatically when it opens the file. That probably isn't happening in the Outlook preview.

Try setting the row height explicitly and see if the result is different:

#include "xlsxwriter.h"

int main() {
    lxw_workbook  *workbook  = workbook_new("wrap.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    lxw_format *wrap_format = workbook_add_format(workbook);
    format_set_text_wrap(wrap_format);

    worksheet_write_string(worksheet, 0, 0, "123\n456", wrap_format);

    /* Add this line. */
    worksheet_set_row(worksheet, 0, 28, NULL);

    workbook_close(workbook);

    return 0;
}

Output in Excel:

screenshot

<!-- gh-comment-id:568328366 --> @jmcnamara commented on GitHub (Dec 23, 2019): Thanks for the sample code. I think I see what the issue may be. When you set word wrap like this Excel resizes the row automatically when it opens the file. That probably isn't happening in the Outlook preview. Try setting the row height explicitly and see if the result is different: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("wrap.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_format *wrap_format = workbook_add_format(workbook); format_set_text_wrap(wrap_format); worksheet_write_string(worksheet, 0, 0, "123\n456", wrap_format); /* Add this line. */ worksheet_set_row(worksheet, 0, 28, NULL); workbook_close(workbook); return 0; } ``` Output in Excel: ![screenshot](https://user-images.githubusercontent.com/94267/71331048-39641000-2528-11ea-8c72-0414f6493a70.png)
Author
Owner

@sirhvd commented on GitHub (Dec 23, 2019):

Thank for your reply.
Set row height will work. But only for static text.
Is there any way to make text wrap work as Excel does?

<!-- gh-comment-id:568329495 --> @sirhvd commented on GitHub (Dec 23, 2019): Thank for your reply. Set row height will work. But only for static text. Is there any way to make text wrap work as Excel does?
Author
Owner

@jmcnamara commented on GitHub (Dec 23, 2019):

Is there any way to make text wrap work as Excel does?

No. This is a calculation that Excel does at run time. It isn't part of the file format so it cannot be controlled from Libxlsxwriter.

The user either has to set the row height explicitly or allow Excel to do it at run time with possible unforeseen actions (like in your case).

Set row height will work. But only for static text.

In that case I will close this issue since we now know why Outlook Preview behaves differently to Excel in this case.

<!-- gh-comment-id:568330211 --> @jmcnamara commented on GitHub (Dec 23, 2019): > Is there any way to make text wrap work as Excel does? No. This is a calculation that Excel does at run time. It isn't part of the file format so it cannot be controlled from Libxlsxwriter. The user either has to set the row height explicitly or allow Excel to do it at run time with possible unforeseen actions (like in your case). > Set row height will work. But only for static text. In that case I will close this issue since we now know why Outlook Preview behaves differently to Excel in this case.
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#206
No description provided.