我尝试使用 xlrd 从 excel 加载一些记录并检查关系。更多详情请参考我的业余代码:
import xlrd
feature_list_file = xlrd.open_workbook('FeatureList.xls')
feature_table = feature_list_file.sheet_by_index(0)
num_feature_rows = feature_table.nrows
num_feature_cols = feature_table.ncols
feature_list = []
for i in range(num_feature_rows):
feature_list.append(feature_table.cell(i, 1))
# print feature_list
issue_list_file = xlrd.open_workbook('IssueList.xls')
issue_table = issue_list_file.sheet_by_index(0)
num_issue_rows = issue_table.nrows
num_issue_cols = issue_table.ncols
epic_list = []
for i in range(num_issue_rows):
if issue_table.cell(i, 0).value == 'Epic':
epic_list.append(issue_table.cell(i, 1).value)
# print epic_list
def check_link(actual_link, parent_list):
result = True
for i in range(parent_list.__len__()):
count = 0
if parent_list[i] in actual_link:
count += 1
if count > 1:
result = False
break
return result
invalid_list = []
for i in range(num_issue_rows):
if issue_table.cell(i, 10).value == '':
invalid_list.append(issue_table.cell(i, 1).value)
else:
if issue_table.cell(i, 0).value == 'Story':
if check_link(issue_table.cell(i, 10).value, epic_list):
invalid_list.append(issue_table.cell(i, 1).value)
if issue_table.cell(i, 0).value == 'Epic':
if check_link(issue_table.cell(i, 10).value, feature_list):
invalid_list.append(issue_table.cell(i, 1).value)
print invalid_list
但是,它总是返回以下消息
Traceback (most recent call last):
File "/Users/sut/PycharmProjects/ItemChecker/JiraItemChecker.py", line 54, in <module>
if check_link(issue_table.cell(i, 10).value, feature_list):
File "/Users/sut/PycharmProjects/ItemChecker/JiraItemChecker.py", line 36, in check_link
if parent_list[i] in actual_link:
TypeError: coercing to Unicode: need string or buffer, Cell found
我该如何解决这个问题?
谢谢