【发布时间】:2018-12-29 00:07:22
【问题描述】:
所以这是我第一次尝试从 Excel 文件中读取数据,并且尝试使用 openpyxl 模块进行读取。我的目标是用嵌套列表作为其值来整理字典。但是,当我尝试运行它时收到此警告时:
用户警告:数据验证扩展不受支持,将被删除 警告(味精)
我不知道我哪里错了。任何帮助将非常感激。谢谢
import openpyxl
try:
wb = openpyxl.load_workbook("Grantfundme Master London.xlsx")
except FileNotFoundError:
print("File could not be found.")
sheet = wb["FUNDS"]
database = {}
for i in range(250):#this is the number of keys I want in my dictionary so loop through rows
charity = sheet.cell(row=i + 1, column=1).value
area_of_work = []
org = []
funding = sheet.cell(row=i + 1, column=14).value
for x in range(8, 13): # this loops through columns with info I need
if sheet.cell(row=i +1, column=x).value !="":
area_of_work.append(sheet.cell(row=i +1, column=x).value)
for y in range(3, 6): # another column loop
if sheet.cell(row=i +1, column=y).value !="":
org.append(sheet.cell(row=i +1, column=y).value)
database[charity] = [area_of_work,org, funding]
try:
f = open("database.txt", "w")
f.close()
except IOError:
print("Ooops. It hasn't written to the file")
【问题讨论】:
-
excel 工作簿中有什么?有条件格式吗?
-
excel 工作簿是来自 openpyxl 模块的对象。我从这里获取我的信息:automatetheboringstuff.com/chapter12
-
是的,我明白这一点。我正在参考 Grantfundme Master London.xlsx 工作簿。该工作簿中有什么类型的数据?另外,另一个问题。您在哪里看到此错误?
-
此警告是否会阻止您对工作表中的数据执行您想要的操作?
-
哦,我看错了,我的错。在工作簿中,只有一些字符串,包括慈善机构的名称、他们的工作领域、他们是什么类型的组织以及他们正在接受的资金。我认为我选择的工作表上没有任何条件格式。该错误没有引用任何行,所以我不知道哪里出错了