我想使用Python Wincom32模塊從工作簿中讀取工作表,但如果工作表數量更多,則無法讀取它。 例如,我有一個Excel工作簿,共有150個工作表,我正在嘗試使用Python Wincom32模塊閱讀第89個Excel工作表,但它給了我一些Excel工作簿中不存在的工作表名稱。 我使用下面的Python代碼想要使用Python讀取工作簿中的工作表Wincom32
import win32com.client
dispatch = win32com.client.Dispatch
excel = dispatch("Excel.Application")
excel.visible = 1
wb = excel.Workbooks.open('<PATH TO EXCEL>')
count = wb.Sheets.count # count stores total number of worksheets present
print count
ws_name = wb.Sheets[ 89 ].name
""" This is supposed to read the name of 89th Worksheet instead it is giving me some garbage
name """
print ws_name
你的代碼適合我。你確定你的wb有150張工作表嗎? count變量打印什麼? – sk11 2014-09-19 06:23:37
你確定你正在打開正確的工作簿嗎?如果它提供了一些工作簿中不存在的工作表名稱,則必須來自_somewhere_;我不認爲Excel正在編寫數據,因爲你抓住它玩遊戲,並打開老闆屏幕。 – abarnert 2014-09-19 08:37:19
@ sk11我的工作簿有150張工作表,count變量給出了輸出爲excel文件中存在的工作表總數。 – pankmish 2014-09-19 09:25:54