openpyxl - 检查工作表是否隐藏 [英] openpyxl - Check if worksheet is hidden

查看:173
本文介绍了openpyxl - 检查工作表是否隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的 excel 文件,我只想处理未隐藏的工作表,我想忽略所有隐藏的工作表.

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.

目前我的 python 脚本会遍历每张工作表,不管它是否隐藏.有没有一种简单的方法可以检查工作表是否被隐藏?

Currently my python script loops through every sheet regardless of whether or not it's hidden. 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.

推荐答案

您可以使用 ws.sheet_state 来查看工作表是 hidden 还是 visible.

You can use ws.sheet_state to find out whether the worksheet is hidden or 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...

这篇关于openpyxl - 检查工作表是否隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆