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.

ENH: Adding 'hidden=True' to 'to_excel', or efficiently hiding some excel tabs?

See original GitHub issue

I need to hide some excel tabs in an output from to_excel, and I’d like to do that with a parameter like hidden=True, but no such parameter exists. The only solution I can find is hiding the sheet manually with openpyxl, but this is prohibitively slow for large files.

My StackOverflow question on this is unanswered, which suggests I’m out of luck.

Testing openpyxl showed that we can’t save .xlsxs without at least one visible tab, so it looks like this would only work like so:

writer = pd.ExcelWriter(filename, engine='xlsxwriter') 
with writer:
    df.to_excel(writer, sheet_name='df')
    df.to_excel(writer, sheet_name='2nd tab')

Would adding hidden=True to to_excel be practical?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jmcnamaracommented, Apr 19, 2021

My issue is solved but I still think hidden=True is more elegant and beginner friendly than his answer, although I don’t know what technical complications that might involve.

There are some potential issues with this proposal. The first is that any parameter added to to_excel() has to be supported by all the Excel engines. In addition, there are a lot of parameters and methods that are exposed by XlsxWriter and OpenPyXL (and xlwt) and it wouldn’t be feasible to add them all to the to_excel() interface (in fact it probably already has too many). Finally, there is a technical issue where hiding the active worksheet without activating another worksheet would generate a “corrupt” Excel file that would open with errors.

So my vote is to close this as can’t fix/won’t fix. Apologies in advance.

0reactions
rhshadrachcommented, Apr 21, 2021

I don’t think there is any further action required here - @chrisjdixon thanks for the report! If you feel something is still unresolved, simply reply here and can reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hide or Unhide worksheets - Microsoft Support
Learn to hide (or unhide) worksheet tabs or workbooks in Excel. ... Right-click the sheet tab you want to hide, or any visible...
Read more >
Pandas to_excel with sheets being hidden, or efficiently hiding ...
I'd like to add something like hidden=True to a sheet condition but pandas doesn't seem to support this. We can do this manually...
Read more >
Pandas To_Excel With Sheets Being Hidden, Or Efficiently ...
Ask questionsENH: Adding 'hiddenTrue' to 'toexcel' or efficiently hiding some excel tabs? I need to hide some excel tabs in an output from...
Read more >
How to make Excel worksheet very hidden and unhide it
All you have to do is right-click any visible worksheet, click Unhide, and select the sheet you want to view. Very hidden sheets...
Read more >
11 Ways to Hide a Sheet in Microsoft Excel
This post is going to show you all the ways to hide any sheet tab in your workbook. Excel allows users to create...
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