简体   繁体   中英

How to read hidden tab of excel workbook in python?

There are 3 different tabs in the workbook I am trying to read via python workbook.xlsm: x, y, z (z is hidden in excel).

import pandas as pd

file=f'S:\filelocation\...\workbook.xlsm'
ws=pd.ExcelFile(file)
ds=pd.read_excel(ws,'z',index=0).fillna(0)

this code returns "ValueError: 'z' is not in list" as z is a hidden tab. "XLRDError: No sheet named <'z'>"

How do I go around this problem?

By default pandas will read all sheets. Probably it may be ' Sheet 3 'instead of 'sheet 3' (s caps)

import pandas as pd

xls = pd.ExcelFile('excel.xlsx')

sheets = xls.book.sheets()
print(sheets)

Then check the visibility of each sheet for sheet in sheets: print(sheet.name, sheet.visibility)

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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