我在 xlsxwriter 工作时遇到了创建下拉列表的问题。数据验证没有出现,即使我确信我已经掌握了代码的要点。我开始于:
def english_fluency(pd_df, source):
"""data validation for english fluency"""
writer = pd.ExcelWriter(source, engine='xlsxwriter')
pd_df.to_excel(writer, sheet_name='Verification', index=False)
workbook = writer.book
worksheet = writer.sheets['Verification']
worksheet.data_validation('E2', {'validate': 'list',
'source': [' ', '1', '2',
'3', '4']})
workbook.save()
workbook.close()
因为我觉得我一直在碰壁,所以我决定切换到 openpyxl 来尝试更简洁地完成同样的事情:
def english_fluency_dv(ws):
"""data validation for english fluency"""
dv_ef = DataValidation(type="list", formula1='"1,2,3,4"', allow_blank=True, showDropDown=True)
ws.add_data_validation(dv_ef)
return ws
我仍然看不到数据验证下拉列表,也许我遗漏了什么或者把它放在了 Excel 工作表的错误区域?
侃侃无极
相关分类