列標題我有一個Excel電子表格,看起來像這樣:解析在Excel工作表中使用Python
Row1 : some text
some other row : "ABC Col" "DEF Col" "GHI Col" "JKL Col"
following rows : more text
我試圖找到包含ABC和JKL行。請注意我傳遞的字符串可能與精確的列標題不匹配。
我使用xlrd
和正在做這樣的事情:
setOfheadings = set(['ABC', 'JKL'])
found_header = False
for i in range(1,sheet.nrows):
if ((not found_header)):
setOfRowValues = set([element.upper() for element in sheet.row_values(i)])
if len(setOfheadings.intersection(setOfRowValues)) == len(setOfheadings):
(found_header, header_row) = (True,i)
由於「ABC」不完全在電子表格中匹配「ABC上校」。它失敗。它適用於我的setOfheadings
包含完全匹配。
任何想法,我怎麼可以做一個正則表達式匹配集交集?
這個問題與Excel或xlrd無關;標籤已移除。 – 2012-03-09 09:18:26