question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: read_excel sheet_name argument

See original GitHub issue

I would love to be able to only read in un-hidden sheets. this could be a new possible value that can be passed to the sheet_name argument.

alternatively, what would also solve my problem is some way to filter the columns (again, probably for sheet_name). ideally be able to use regex or string comparison to choose which sheets to read.

also, what about being able to specify which sheets to be ignored?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ahawrylukcommented, Aug 4, 2021

@rhshadrach yes, at least for .xls and .xlsx/.xlsm files, checking for hidden sheets is really easy ahead of time:

wb = xlrd.open_workbook('myfile.xls')
sheets = [sheet.name for sheet in wb.sheets() if sheet.visibility == 0]
dfs = pd.read_excel(wb, sheets)

wb = openpyxl.open('myfile.xlsx', read_only=True, data_only=True)
sheets = [sheet.title for sheet in wb if sheet.sheet_state == 'visible']
dfs = pd.read_excel(wb, sheets)
wb.close()

I like your cookbook suggestion; I’ll make a very small PR.

1reaction
gfyoungcommented, Feb 23, 2018

@tres-pitt : Thanks for the report! Let me dissect this a bit:

  1. Checking for whether a sheet is hidden would be tricky unless we were somehow able to surface an attribute for visibility. Not sure if that’s something we have available, but open to investigation.

  2. Your suggestion of regex wouldn’t be particularly hard to add, though I’m not sure how great the use-case would be for such an enhancement. Regex is not a very user-friendly option for most.

  3. I’m more a fan of your suggestion to skip sheets. We do this with columns, so I don’t see why we couldn’t do the same with Excel sheets.

So IMO 1 and 3 would be the best ways to go, with 3 being the easiest to implement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.read_excel — pandas 1.5.2 documentation
Supports an option to read a single sheet or a list of sheets. Parameters. iostr, bytes, ExcelFile, xlrd.Book, path object, or file-like object....
Read more >
Using Pandas to pd.read_excel() for multiple worksheets of ...
Note that the sheet_name argument to pd.read_excel() can be the name of the sheet (as above), an integer specifying the sheet number (eg...
Read more >
Error message when you open or save a file in Microsoft Excel
This error message occurs when you save or open a file if the path to the file (including the file name) exceeds 218...
Read more >
How to correct a #NAME? error - Microsoft Support
Solution: Define a name in Name Manager, and then add the name to the formula. Follow these steps to do that: If you...
Read more >
Data Factory XLSX Wildcard File Path Used but I cant ...
Here is an existing feature request from ADF user voice forum submitted by other users - Get list of Excel sheet names.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found