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

pylightxl.Database.ws_names returns incorrect sheet names in some cases #75

Closed
flc opened this issue Oct 13, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@flc
Copy link

flc commented Oct 13, 2022

Pylightxl Version: 1.60
Python Version: 3.9.14

Code to reproduce the problem:

import pylightxl

path = 'test_sheet.xlsx'
db = pylightxl.readxl(fn=path)
print(db.ws_names)

The output is:

["'#3969'", '#3969']

However the file contains only 1 sheet named #3969.
The weird thing is that if I rename the sheet to sheet for example, save it in LibreOffice (see the attached test_sheet_rename.xlsx), then I get from the above code what is expected: ws_names return only 1 sheet named sheet.

test_sheet.xlsx
test_sheet_rename.xlsx

@flc
Copy link
Author

flc commented Oct 18, 2022

The problem seems to be the difference between these two in xl\workbook.xml:

<sheet name="#3969" sheetId="1" state="visible" r:id="rId2"/>
<definedName function="false" hidden="true" localSheetId="0" name="_xlnm._FilterDatabase" vbProcedure="false">&apos;#3969&apos;!$D$1:$D$963</definedName>

because
#3969 != &apos;#3969&apos; aka '#3969'

Maybe some excel programs put the sheet name between the apostrophes? At least in the xml they write. But I don't know which ones. It's weird.

But for some reason other parsers can handle this situation:

xlrd==1.2.0:

In [1]: import xlrd
In [2]: wb = xlrd.open_workbook('test_sheet.xlsx')
In [4]: wb.sheet_names()
Out[4]: [u'#3969']

openpyxl==3.0.10:

In [1]: import openpyxl
In [2]: wb = openpyxl.load_workbook(filename='test_sheet.xlsx')
In [4]: wb.sheetnames
Out[4]: ['#3969']

@alexlawriewood
Copy link

I also noticed this as a regression when moving from 1.59 to 1.60, working with an Excel spreadsheet exported by an inventory tool.

@PydPiper
Copy link
Owner

PydPiper commented Jan 1, 2023

@flc and @alexlawriewood Thank you for bringing this to our attention! Sorry about the delay, but i just had a chance to look into this and i am rolling out 1.61 that will fix this issue!

@PydPiper PydPiper self-assigned this Jan 1, 2023
@PydPiper PydPiper added the bug Something isn't working label Jan 1, 2023
@PydPiper PydPiper closed this as completed Jan 1, 2023
@flc
Copy link
Author

flc commented Jan 3, 2023

Hi @PydPiper, thanks very much for the fix!
However, I briefly checked the fixed code and I wonder what happens if a sheet name actually contains a single quote. I think that would lead to an incorrect behavior again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants