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: No exception when adding two autofilters #1102

Open
1 task done
rhshadrach-8451 opened this issue Nov 26, 2024 · 1 comment
Open
1 task done

Bug: No exception when adding two autofilters #1102

rhshadrach-8451 opened this issue Nov 26, 2024 · 1 comment
Assignees
Labels

Comments

@rhshadrach-8451
Copy link

Current behavior

In converting code from pandas to Polars, I neglected to see that Polars adds autofilters by default in write_excel. My prior code was adding autofilters manually via xlsxwriter. Thus switching to Polars, autofilters were being added twice. The Python code ran fine, but when opening the resulting workbook Excel needed to repair the file. The log stated:

Removed Feature: AutoFilter from /xl/tables/table1.xml part (Table)
Removed Feature: Table from /xl/tables/table1.xml part (Table)

Took me a bit to figure out what was going on.

Expected behavior

Not necessarily expected, but perhaps more desirable would be for xlsxwriter to detect the situation (assuming my diagnosis is correct - which I am not certain of) and raise an informative error message.

Not sure if this is feasible - if it isn't, then I thought just having this (closed) issue with the error message would possibly let others stumble upon a potential somewhat common case (switching from pandas to Polars).

Sample code to reproduce

import polars as pl
import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
df = pl.DataFrame({"a": [1, 1, 2], "b": [3, 4, 5]})
df.write_excel(workbook, worksheet="A")
ws = workbook.get_worksheet_by_name("A")
ws.autofilter(0, 0, len(df)-1, len(df.columns)-1)
workbook.close()

Environment

- XlsxWriter version: 3.2.0
- Python version: 3.10.15
- Excel version: 16.91
- OS: macOS 14.7

Any other information

This might be similar to:

OpenOffice and LibreOffice users

  • I have tested the output file with Excel.
@jmcnamara jmcnamara self-assigned this Nov 26, 2024
@jmcnamara
Copy link
Owner

Thanks. That is a bug.

The library doesn't allow 2 worksheet autofilters (since Excel doesn't allow it) but it doesn't prevent a worksheet autofilter and a table autofilter from overlapping (which it should do). I'll fix that.

Thanks for the detailed report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants