[GH-ISSUE #3] add cell sets wrong format #3

Closed
opened 2026-05-05 11:22:52 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @LaurinStrelow on GitHub (Feb 27, 2015).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/3

Originally assigned to: @jmcnamara on GitHub.

Hi,

consider this example:

    /* Add a worksheet. */
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Widen the first column to make the text clearer. */
    worksheet_set_column(worksheet, 0, 0, 20, NULL, NULL);

    lxw_format *topLeftBottomFormat = workbook_add_format(workbook);
    format_set_font_size(topLeftBottomFormat, 14);
    format_set_font_name(topLeftBottomFormat, "Arial");
    format_set_bottom(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_left(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_top(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topLeftBottomFormat, LXW_COLOR_BLACK);


    lxw_format *topBottomFormat = workbook_add_format(workbook);
    format_set_font_size(topBottomFormat, 14);
    format_set_font_name(topBottomFormat, "Arial");
    format_set_bottom(topBottomFormat, LXW_BORDER_MEDIUM);
    format_set_top(topBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topBottomFormat, LXW_COLOR_BLACK);


    lxw_format *topLeftFormat = workbook_add_format(workbook);
    format_set_font_size(topLeftFormat, 14);
    format_set_font_name(topLeftFormat, "Arial");
    format_set_left(topLeftFormat, LXW_BORDER_MEDIUM);
    format_set_top(topLeftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topLeftFormat, LXW_COLOR_BLACK);


    lxw_format *bottomLeftFormat = workbook_add_format(workbook);
    format_set_font_size(bottomLeftFormat, 14);
    format_set_font_name(bottomLeftFormat, "Arial");
    format_set_bottom(bottomLeftFormat, LXW_BORDER_MEDIUM);
    format_set_left(bottomLeftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(bottomLeftFormat, LXW_COLOR_BLACK);


    lxw_format *leftFormat = workbook_add_format(workbook);
    format_set_font_size(leftFormat, 14);
    format_set_font_name(leftFormat, "Arial");
    format_set_left(leftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(leftFormat, LXW_COLOR_BLACK);

    lxw_format *thinFormat = workbook_add_format(workbook);
    format_set_font_size(thinFormat, 14);
    format_set_font_name(thinFormat, "Arial");
    format_set_border(thinFormat, LXW_BORDER_THIN);
    format_set_border_color(thinFormat, LXW_COLOR_BLACK);
    format_set_align(thinFormat, LXW_ALIGN_CENTER);

    lxw_format *thinTopFormat = workbook_add_format(workbook);
    format_set_font_size(thinTopFormat, 14);
    format_set_font_name(thinTopFormat, "Arial");
    format_set_border(thinTopFormat, LXW_BORDER_THIN);
    format_set_top(thinTopFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(thinTopFormat, LXW_COLOR_BLACK);
    format_set_align(thinTopFormat, LXW_ALIGN_CENTER);

    lxw_format *thinBottomFormat = workbook_add_format(workbook);
    format_set_font_size(thinBottomFormat, 14);
    format_set_font_name(thinBottomFormat, "Arial");
    format_set_border(thinBottomFormat, LXW_BORDER_THIN);
    format_set_bottom(thinBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(thinBottomFormat, LXW_COLOR_BLACK);
    format_set_align(thinBottomFormat, LXW_ALIGN_CENTER);

    worksheet_write_string(worksheet, 1, 20, "test", topLeftBottomFormat);
    worksheet_write_string(worksheet, 1, 22, "test", topLeftFormat);
    worksheet_write_string(worksheet, 1, 24, "test", topBottomFormat);
    worksheet_write_string(worksheet, 1, 26, "test", leftFormat);
    worksheet_write_string(worksheet, 1, 28, "test", bottomLeftFormat);
    worksheet_write_string(worksheet, 1, 30, "test", thinBottomFormat);
    worksheet_write_string(worksheet, 1, 32, "test", thinFormat);
    worksheet_write_string(worksheet, 1, 34, "test", thinTopFormat); 

This is the result i get:
excel_bug

You may note that the the cells are generated with the wrong format.
This is how it should look like:

excel_correct

I generated the second worksheet with this following code:

    /* Add a worksheet. */
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Widen the first column to make the text clearer. */
    worksheet_set_column(worksheet, 0, 0, 20, NULL, NULL);

    lxw_format *topLeftBottomFormat = workbook_add_format(workbook);
    format_set_font_size(topLeftBottomFormat, 14);
    format_set_font_name(topLeftBottomFormat, "Arial");
    format_set_bottom(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_left(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_top(topLeftBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topLeftBottomFormat, LXW_COLOR_BLACK);

    lxw_format *topLeftFormat = workbook_add_format(workbook);
    format_set_font_size(topLeftFormat, 14);
    format_set_font_name(topLeftFormat, "Arial");
    format_set_left(topLeftFormat, LXW_BORDER_MEDIUM);
    format_set_top(topLeftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topLeftFormat, LXW_COLOR_BLACK);

    lxw_format *topBottomFormat = workbook_add_format(workbook);
    format_set_font_size(topBottomFormat, 14);
    format_set_font_name(topBottomFormat, "Arial");
    format_set_bottom(topBottomFormat, LXW_BORDER_MEDIUM);
    format_set_top(topBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(topBottomFormat, LXW_COLOR_BLACK);

    lxw_format *leftFormat = workbook_add_format(workbook);
    format_set_font_size(leftFormat, 14);
    format_set_font_name(leftFormat, "Arial");
    format_set_left(leftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(leftFormat, LXW_COLOR_BLACK);

    lxw_format *bottomLeftFormat = workbook_add_format(workbook);
    format_set_font_size(bottomLeftFormat, 14);
    format_set_font_name(bottomLeftFormat, "Arial");
    format_set_bottom(bottomLeftFormat, LXW_BORDER_MEDIUM);
    format_set_left(bottomLeftFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(bottomLeftFormat, LXW_COLOR_BLACK);

    lxw_format *thinBottomFormat = workbook_add_format(workbook);
    format_set_font_size(thinBottomFormat, 14);
    format_set_font_name(thinBottomFormat, "Arial");
    format_set_border(thinBottomFormat, LXW_BORDER_THIN);
    format_set_bottom(thinBottomFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(thinBottomFormat, LXW_COLOR_BLACK);
    format_set_align(thinBottomFormat, LXW_ALIGN_CENTER);

    lxw_format *thinFormat = workbook_add_format(workbook);
    format_set_font_size(thinFormat, 14);
    format_set_font_name(thinFormat, "Arial");
    format_set_border(thinFormat, LXW_BORDER_THIN);
    format_set_border_color(thinFormat, LXW_COLOR_BLACK);
    format_set_align(thinFormat, LXW_ALIGN_CENTER);

    lxw_format *thinTopFormat = workbook_add_format(workbook);
    format_set_font_size(thinTopFormat, 14);
    format_set_font_name(thinTopFormat, "Arial");
    format_set_border(thinTopFormat, LXW_BORDER_THIN);
    format_set_top(thinTopFormat, LXW_BORDER_MEDIUM);
    format_set_border_color(thinTopFormat, LXW_COLOR_BLACK);
    format_set_align(thinTopFormat, LXW_ALIGN_CENTER);



    worksheet_write_string(worksheet, 1, 20, "test", topLeftBottomFormat);
    worksheet_write_string(worksheet, 1, 22, "test", topLeftFormat);
    worksheet_write_string(worksheet, 1, 24, "test", topBottomFormat);
    worksheet_write_string(worksheet, 1, 26, "test", leftFormat);
    worksheet_write_string(worksheet, 1, 28, "test", bottomLeftFormat);
    worksheet_write_string(worksheet, 1, 30, "test", thinBottomFormat);
    worksheet_write_string(worksheet, 1, 32, "test", thinFormat);
    worksheet_write_string(worksheet, 1, 34, "test", thinTopFormat);

Here are the workbook_add_format calls in the same direction, as i later use this format in the worksheet_write_string call. This is not the case in the first code example. The bug happens with every worksheet_write_* method.
I also think that this is not bounded to the border style, rather to every style you can set (font, background color, ..).

This example is little bit large, i hope that the issue became clear to you.
This bug happens with and without memory optimization.
If you prioritize which issue you work first on, this is more important for me.
If there is something else i can do to help you, feel free to asks.

Thank you!

Originally created by @LaurinStrelow on GitHub (Feb 27, 2015). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/3 Originally assigned to: @jmcnamara on GitHub. Hi, consider this example: ``` c /* Add a worksheet. */ lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); /* Widen the first column to make the text clearer. */ worksheet_set_column(worksheet, 0, 0, 20, NULL, NULL); lxw_format *topLeftBottomFormat = workbook_add_format(workbook); format_set_font_size(topLeftBottomFormat, 14); format_set_font_name(topLeftBottomFormat, "Arial"); format_set_bottom(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_left(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_top(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(topLeftBottomFormat, LXW_COLOR_BLACK); lxw_format *topBottomFormat = workbook_add_format(workbook); format_set_font_size(topBottomFormat, 14); format_set_font_name(topBottomFormat, "Arial"); format_set_bottom(topBottomFormat, LXW_BORDER_MEDIUM); format_set_top(topBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(topBottomFormat, LXW_COLOR_BLACK); lxw_format *topLeftFormat = workbook_add_format(workbook); format_set_font_size(topLeftFormat, 14); format_set_font_name(topLeftFormat, "Arial"); format_set_left(topLeftFormat, LXW_BORDER_MEDIUM); format_set_top(topLeftFormat, LXW_BORDER_MEDIUM); format_set_border_color(topLeftFormat, LXW_COLOR_BLACK); lxw_format *bottomLeftFormat = workbook_add_format(workbook); format_set_font_size(bottomLeftFormat, 14); format_set_font_name(bottomLeftFormat, "Arial"); format_set_bottom(bottomLeftFormat, LXW_BORDER_MEDIUM); format_set_left(bottomLeftFormat, LXW_BORDER_MEDIUM); format_set_border_color(bottomLeftFormat, LXW_COLOR_BLACK); lxw_format *leftFormat = workbook_add_format(workbook); format_set_font_size(leftFormat, 14); format_set_font_name(leftFormat, "Arial"); format_set_left(leftFormat, LXW_BORDER_MEDIUM); format_set_border_color(leftFormat, LXW_COLOR_BLACK); lxw_format *thinFormat = workbook_add_format(workbook); format_set_font_size(thinFormat, 14); format_set_font_name(thinFormat, "Arial"); format_set_border(thinFormat, LXW_BORDER_THIN); format_set_border_color(thinFormat, LXW_COLOR_BLACK); format_set_align(thinFormat, LXW_ALIGN_CENTER); lxw_format *thinTopFormat = workbook_add_format(workbook); format_set_font_size(thinTopFormat, 14); format_set_font_name(thinTopFormat, "Arial"); format_set_border(thinTopFormat, LXW_BORDER_THIN); format_set_top(thinTopFormat, LXW_BORDER_MEDIUM); format_set_border_color(thinTopFormat, LXW_COLOR_BLACK); format_set_align(thinTopFormat, LXW_ALIGN_CENTER); lxw_format *thinBottomFormat = workbook_add_format(workbook); format_set_font_size(thinBottomFormat, 14); format_set_font_name(thinBottomFormat, "Arial"); format_set_border(thinBottomFormat, LXW_BORDER_THIN); format_set_bottom(thinBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(thinBottomFormat, LXW_COLOR_BLACK); format_set_align(thinBottomFormat, LXW_ALIGN_CENTER); worksheet_write_string(worksheet, 1, 20, "test", topLeftBottomFormat); worksheet_write_string(worksheet, 1, 22, "test", topLeftFormat); worksheet_write_string(worksheet, 1, 24, "test", topBottomFormat); worksheet_write_string(worksheet, 1, 26, "test", leftFormat); worksheet_write_string(worksheet, 1, 28, "test", bottomLeftFormat); worksheet_write_string(worksheet, 1, 30, "test", thinBottomFormat); worksheet_write_string(worksheet, 1, 32, "test", thinFormat); worksheet_write_string(worksheet, 1, 34, "test", thinTopFormat); ``` This is the result i get: ![excel_bug](https://cloud.githubusercontent.com/assets/1918073/6415608/683fcb7e-bea0-11e4-9933-1d6651cb5cfe.png) You may note that the the cells are generated with the wrong format. This is how it should look like: ![excel_correct](https://cloud.githubusercontent.com/assets/1918073/6415784/786540fa-bea1-11e4-9020-df866c44eea6.png) I generated the second worksheet with this following code: ``` c /* Add a worksheet. */ lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); /* Widen the first column to make the text clearer. */ worksheet_set_column(worksheet, 0, 0, 20, NULL, NULL); lxw_format *topLeftBottomFormat = workbook_add_format(workbook); format_set_font_size(topLeftBottomFormat, 14); format_set_font_name(topLeftBottomFormat, "Arial"); format_set_bottom(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_left(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_top(topLeftBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(topLeftBottomFormat, LXW_COLOR_BLACK); lxw_format *topLeftFormat = workbook_add_format(workbook); format_set_font_size(topLeftFormat, 14); format_set_font_name(topLeftFormat, "Arial"); format_set_left(topLeftFormat, LXW_BORDER_MEDIUM); format_set_top(topLeftFormat, LXW_BORDER_MEDIUM); format_set_border_color(topLeftFormat, LXW_COLOR_BLACK); lxw_format *topBottomFormat = workbook_add_format(workbook); format_set_font_size(topBottomFormat, 14); format_set_font_name(topBottomFormat, "Arial"); format_set_bottom(topBottomFormat, LXW_BORDER_MEDIUM); format_set_top(topBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(topBottomFormat, LXW_COLOR_BLACK); lxw_format *leftFormat = workbook_add_format(workbook); format_set_font_size(leftFormat, 14); format_set_font_name(leftFormat, "Arial"); format_set_left(leftFormat, LXW_BORDER_MEDIUM); format_set_border_color(leftFormat, LXW_COLOR_BLACK); lxw_format *bottomLeftFormat = workbook_add_format(workbook); format_set_font_size(bottomLeftFormat, 14); format_set_font_name(bottomLeftFormat, "Arial"); format_set_bottom(bottomLeftFormat, LXW_BORDER_MEDIUM); format_set_left(bottomLeftFormat, LXW_BORDER_MEDIUM); format_set_border_color(bottomLeftFormat, LXW_COLOR_BLACK); lxw_format *thinBottomFormat = workbook_add_format(workbook); format_set_font_size(thinBottomFormat, 14); format_set_font_name(thinBottomFormat, "Arial"); format_set_border(thinBottomFormat, LXW_BORDER_THIN); format_set_bottom(thinBottomFormat, LXW_BORDER_MEDIUM); format_set_border_color(thinBottomFormat, LXW_COLOR_BLACK); format_set_align(thinBottomFormat, LXW_ALIGN_CENTER); lxw_format *thinFormat = workbook_add_format(workbook); format_set_font_size(thinFormat, 14); format_set_font_name(thinFormat, "Arial"); format_set_border(thinFormat, LXW_BORDER_THIN); format_set_border_color(thinFormat, LXW_COLOR_BLACK); format_set_align(thinFormat, LXW_ALIGN_CENTER); lxw_format *thinTopFormat = workbook_add_format(workbook); format_set_font_size(thinTopFormat, 14); format_set_font_name(thinTopFormat, "Arial"); format_set_border(thinTopFormat, LXW_BORDER_THIN); format_set_top(thinTopFormat, LXW_BORDER_MEDIUM); format_set_border_color(thinTopFormat, LXW_COLOR_BLACK); format_set_align(thinTopFormat, LXW_ALIGN_CENTER); worksheet_write_string(worksheet, 1, 20, "test", topLeftBottomFormat); worksheet_write_string(worksheet, 1, 22, "test", topLeftFormat); worksheet_write_string(worksheet, 1, 24, "test", topBottomFormat); worksheet_write_string(worksheet, 1, 26, "test", leftFormat); worksheet_write_string(worksheet, 1, 28, "test", bottomLeftFormat); worksheet_write_string(worksheet, 1, 30, "test", thinBottomFormat); worksheet_write_string(worksheet, 1, 32, "test", thinFormat); worksheet_write_string(worksheet, 1, 34, "test", thinTopFormat); ``` Here are the `workbook_add_format` calls in the same direction, as i later use this format in the `worksheet_write_string` call. This is not the case in the first code example. The bug happens with every `worksheet_write_*` method. I also think that this is not bounded to the border style, rather to every style you can set (font, background color, ..). This example is little bit large, i hope that the issue became clear to you. This bug happens with and without memory optimization. If you prioritize which issue you work first on, this is more important for me. If there is something else i can do to help you, feel free to asks. Thank you!
gitea-mirror 2026-05-05 11:22:52 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jmcnamara commented on GitHub (Feb 27, 2015):

Hi Laurin,

Thanks, I'll take a look at it.

John

<!-- gh-comment-id:76426254 --> @jmcnamara commented on GitHub (Feb 27, 2015): Hi Laurin, Thanks, I'll take a look at it. John
Author
Owner

@jmcnamara commented on GitHub (Mar 1, 2015):

Hi,

I've pushed a fix for this to master. I've included a test case based on your report but you can verify it yourself and let me know.

Thanks for the bug report.

John

<!-- gh-comment-id:76595175 --> @jmcnamara commented on GitHub (Mar 1, 2015): Hi, I've pushed a fix for this to master. I've included a test case based on your report but you can verify it yourself and let me know. Thanks for the bug report. John
Author
Owner

@LaurinStrelow commented on GitHub (Mar 1, 2015):

Hi,

everything is now working as expected.

Thank you!

<!-- gh-comment-id:76615460 --> @LaurinStrelow commented on GitHub (Mar 1, 2015): Hi, everything is now working as expected. Thank you!
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#3
No description provided.