add cell sets wrong format #3

Closed
LaurinStrelow opened this Issue Feb 27, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@LaurinStrelow

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!

@jmcnamara jmcnamara self-assigned this Feb 27, 2015

@jmcnamara jmcnamara added the bug label Feb 27, 2015

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Feb 27, 2015

Owner

Hi Laurin,

Thanks, I'll take a look at it.

John

Owner

jmcnamara commented Feb 27, 2015

Hi Laurin,

Thanks, I'll take a look at it.

John

jmcnamara added a commit that referenced this issue Mar 1, 2015

Fix for format ordering
Fix format objects so that they are written to the file in the
order of used rather than the order the of creation. This bug
caused incorrect formats in cells.

Issue #3
@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Mar 1, 2015

Owner

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

Owner

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

@LaurinStrelow

This comment has been minimized.

Show comment
Hide comment
@LaurinStrelow

LaurinStrelow Mar 1, 2015

Hi,

everything is now working as expected.

Thank you!

Hi,

everything is now working as expected.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment