【问题标题】:How to read a checkbox's value in a excel file by django?如何通过 django 读取 excel 文件中的复选框值?
【发布时间】:2013-06-29 07:23:08
【问题描述】:

我有一个这样的excel文件,excel文件中有一些复选框。

我正在使用 django 和 Python Excel(xlrd/xlwt/xlutils)

问题一,我要读取复选框的值,怎么办??

问题二,如何更新复选框的值??

【问题讨论】:

    标签: django excel checkbox


    【解决方案1】:

    您无法使用 Python Excel(xlrd、xlwt、xltutils)读取或修改复选框。

    如果您在 Windows 平台上,您可以使用pywin32,也可以使用pyxll

    请参阅下面读取复选框值的可能示例,设置复选框值只需更改 for 循环中的语句为cb.Value = 1cb.Value = 0

    import win32com.client as win32
    excel = win32.gencache.EnsureDispatch('Excel.Application')
    wb = excel.Workbooks.Open(r'U:\Example.xls')
    ws = wb.Worksheets("Sheet1")
    cb_dict = {}
    for cb in ws.CheckBoxes():
        cb_dict[cb.Name] = cb.Value
    excel.Application.Quit()
    

    有关 pyxll 示例,请参阅 herehere

    【讨论】:

    • 请注意,第3行应该使用excel而不是xl
    猜你喜欢
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 2011-05-27
    • 2017-04-18
    • 1970-01-01
    相关资源
    最近更新 更多