[GH-ISSUE #374] Auto-filter combined with merged cells broken #300

Closed
opened 2026-05-05 12:07:16 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @znakeeye on GitHub (May 27, 2022).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/374

Originally assigned to: @jmcnamara on GitHub.

Using libxlsxwriter 1.1.4. Consider the sample below. When merging cells, the auto-filter produces incorrect filter setup. Toggling the filters in Excel corrects the problem.

#include "xlsxwriter.h"

int main() {

    lxw_workbook* workbook = workbook_new("autofilter.xlsx");
    lxw_worksheet* worksheet = workbook_add_worksheet(workbook, NULL);
    
    worksheet_write_string(worksheet, 0, 0, "A", NULL);
    worksheet_merge_range(worksheet, 0, 1, 0, 2, "B", NULL); // <-- breaks auto-filter
    worksheet_autofilter(worksheet, 0, 0, 0, 1);

    return workbook_close(workbook);
}

Actual:

image

Expected:

image

Originally created by @znakeeye on GitHub (May 27, 2022). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/374 Originally assigned to: @jmcnamara on GitHub. Using `libxlsxwriter 1.1.4`. Consider the sample below. When merging cells, the auto-filter produces incorrect filter setup. Toggling the filters in Excel corrects the problem. ```c #include "xlsxwriter.h" int main() { lxw_workbook* workbook = workbook_new("autofilter.xlsx"); lxw_worksheet* worksheet = workbook_add_worksheet(workbook, NULL); worksheet_write_string(worksheet, 0, 0, "A", NULL); worksheet_merge_range(worksheet, 0, 1, 0, 2, "B", NULL); // <-- breaks auto-filter worksheet_autofilter(worksheet, 0, 0, 0, 1); return workbook_close(workbook); } ``` **Actual:** ![image](https://user-images.githubusercontent.com/958469/170712882-6aebecb2-9b3b-4007-ade0-a32b42058e9f.png) **Expected:** ![image](https://user-images.githubusercontent.com/958469/170712969-19d6b313-500a-488e-b3fb-500a4c64dd0c.png)
Author
Owner

@jmcnamara commented on GitHub (May 27, 2022):

Thanks for the detailed sample code.

This looks like a bit of an unusual use case. You can almost get what you want by extending the autofilter to column C (which strictly speaking is where is should be):

#include "xlsxwriter.h"

int main() {

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

    worksheet_write_string(worksheet, 0, 0, "A", NULL);
    worksheet_merge_range(worksheet, 0, 1, 0, 2, "B", NULL);
    worksheet_autofilter(worksheet, 0, 0, 0, 2); // Changed here.

    return workbook_close(workbook);
}

This give the following output:

screenshot

However, it has an additional filter arrow in column B that you don't want (based on your Expected image). Turning off the filter arrow for a column is not currently supported by any of the xlsxwriter variants. So you'll probably need to find some other way to represent the functionality that you want.

<!-- gh-comment-id:1139989228 --> @jmcnamara commented on GitHub (May 27, 2022): Thanks for the detailed sample code. This looks like a bit of an unusual use case. You can almost get what you want by extending the autofilter to column C (which strictly speaking is where is should be): ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("merge_filter03.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); worksheet_write_string(worksheet, 0, 0, "A", NULL); worksheet_merge_range(worksheet, 0, 1, 0, 2, "B", NULL); worksheet_autofilter(worksheet, 0, 0, 0, 2); // Changed here. return workbook_close(workbook); } ``` This give the following output: ![screenshot](https://user-images.githubusercontent.com/94267/170781189-ffb4c94c-1434-4ab2-872b-5cf49f33ed9f.png) However, it has an additional filter arrow in column B that you don't want (based on your Expected image). Turning off the filter arrow for a column is not currently supported by any of the xlsxwriter variants. So you'll probably need to find some other way to represent the functionality that you want.
Author
Owner

@znakeeye commented on GitHub (May 27, 2022):

In Excel 365 you simply cannot create the result you get from xlsxwriter, and vice versa. How come? Doesn't libxlsxwriter strive for 100% Excel compatibility?

If we compare the files (before and after clicking the button in Excel), maybe we can find the trick.

<!-- gh-comment-id:1140023257 --> @znakeeye commented on GitHub (May 27, 2022): In Excel 365 you simply cannot create the result you get from xlsxwriter, and vice versa. How come? Doesn't libxlsxwriter strive for 100% Excel compatibility? If we compare the files (before and after clicking the button in Excel), maybe we can find the trick.
Author
Owner

@jmcnamara commented on GitHub (May 27, 2022):

How come?

There is a autoFilter xml attribute called showButton that is used by Excel to hide one of the filter arrows. It is usually only accessible via VBA. I'm surprised that it can be enabled like this.

What is the use case a merged autofilter?

<!-- gh-comment-id:1140041100 --> @jmcnamara commented on GitHub (May 27, 2022): > How come? There is a autoFilter xml attribute called showButton that is used by Excel to hide one of the filter arrows. It is usually only accessible via VBA. I'm surprised that it can be enabled like this. What is the use case a merged autofilter?
Author
Owner

@jmcnamara commented on GitHub (Jun 4, 2022):

Unfortunately, this is too much of an edge case to support. Closing until there are more requests for it and a definite use case.

<!-- gh-comment-id:1146634255 --> @jmcnamara commented on GitHub (Jun 4, 2022): Unfortunately, this is too much of an edge case to support. Closing until there are more requests for it and a definite use 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#300
No description provided.