我有一個現有的代碼,它使用 Pandas 來讀取 Excel 作業簿。它讀取所有作業表,包括隱藏的作業表,但是,我只想閱讀可見的作業表。嘗試使用this,但沒有幫助:
以下是嘗試過的片段。
xlFile = '/path/file_name.xlsx'
xl = pd.ExcelFile(xlFile)
list_of_visible_sheets = []
sheets = xl.book.sheets()
for sheet in sheets:
if sheet.visibility == 0:
list_of_visible_sheets.append(sheets)
print(list_of_visible_sheets)
和
list_of_visible_sheets = []
sheets = xl.sheet_names
for sheet in sheets:
if sheet.visibility == 0:
list_of_visible_sheets.append(sheets)
print(list_of_visible_sheets)
我怎樣才能單獨獲得可見的床單?
uj5u.com熱心網友回復:
嘗試通過sheetname引數pandas.read_excel
如果沒有過多的紙張,您可以手動創建所需的專案,或者從使用的配方是答案,lambda運算式。
uj5u.com熱心網友回復:
您可以將此代碼與openpyxl. 它大致完成了 pandasread_excel()函式的作用:
import openpyxl
import pandas as pd
filename = 'TestFile.xlsx'
dfs = { ws.title : pd.DataFrame(ws.values)
for ws in openpyxl.load_workbook(filename,read_only=True).worksheets
if ws.sheet_state != 'hidden' }
print(dfs)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/328278.html
