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

[Bug] Text Wrap in Outlook Preview mode #257

Closed
sirhvd opened this issue Dec 20, 2019 · 6 comments
Closed

[Bug] Text Wrap in Outlook Preview mode #257

sirhvd opened this issue Dec 20, 2019 · 6 comments

Comments

@sirhvd
Copy link

sirhvd commented Dec 20, 2019

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!

@RaFaeL-NN
Copy link

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 #156 . A solution can be with an option changing write mode (from binary to text).

@jmcnamara
Copy link
Owner

@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.

@sirhvd
Copy link
Author

sirhvd commented 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.

@jmcnamara
Copy link
Owner

jmcnamara commented 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

@sirhvd
Copy link
Author

sirhvd commented 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?

@jmcnamara
Copy link
Owner

jmcnamara commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants