這可能是一項簡單的任務,但對於我而言,我找不到解決方案。我有一個有表格的excel文檔。該表中的列都應用了自動篩選器。我想要做的就是能夠選擇該自動過濾器中的所有條目(第9列)並將其存儲在數組中。我正在使用Win32Com。Python-如何在Excel自動篩選器中顯示選擇
import win32com.client as win32
working_dir = 'C:\\invoice\\'
save_dir = 'C:\\test\\'
xl = win32.gencache.EnsureDispatch("Excel.Application")
xl.Visible = True
template_wb = xl.Workbooks.Open(working_dir + 'Settlement report V6-EMPLATE.xlsm')
#Worksheets
orgdata_ws = template_wb.Sheets('Organization Data')
masterdata_ws = template_wb.Sheets('Master Data')
#I want to access the autofilter in column 9 and simply get the contents in the autofilter list and put them in the array
filtercontents = []
thefilter = orgdata_ws.Columns(9).Autofilter
for i in thefilter:
filtercontents.append(i) ?????????
你會得到什麼異常/錯誤? –
嗨拉斐爾,與此特定的代碼,我收到此錯誤: TypeError:'instancemethod'對象不可迭代。 但很有可能我沒有使用正確的方法來實現我的目標。也快速更新我改變了自動過濾器爲自動過濾器:) –