简体   繁体   English

openpyxl-检查工作表是否隐藏

[英]openpyxl - Check if worksheet is hidden

I have a large number of excel files and I only want to work with sheets which are not hidden and I want to ignore all hidden sheets. 我有大量的excel文件,我只想使用未隐藏的工作表,而我想忽略所有隐藏的工作表。

Currently my python script loops through every sheet regardless of whether or not it's hidden. 目前,无论是否隐藏,我的python脚本都会循环遍历每个工作表。 Is there a simple way to check if a worksheet is hidden? 有没有一种简单的方法来检查工作表是否被隐藏?

I've looked online but the only thing I can find is ways to hide/unhide worksheets which I don't want to do here. 我在网上看过,但是我唯一能找到的是隐藏/取消隐藏工作表的方法,而这些我不想在这里做。

You can use ws.sheet_state to find out whether the worksheet is hidden or visible . 您可以使用ws.sheet_state来确定工作表是hidden还是visible

from openpyxl import load_workbook

path = r"your_excel.xlsx"

wb = load_workbook(filename=path)

for i in wb.worksheets:
    if i.sheet_state == "visible":
        #do what you need to...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM