【发布时间】:2019-05-29 04:15:31
【问题描述】:
我有一个读取 Excel 工作表的简单问题,将包含大约 83 列的每一行视为唯一的数据库记录,将其添加到本地数据记录并最终附加并写入 DBF 文件。
我可以从 excel 中提取所有值并将它们添加到列表中。但是列表的语法不正确,我不知道如何准备/将列表转换为数据库记录。我正在使用 Openpyxl、dbf 和 python 3.7。
目前我只是在测试并尝试为第 3 行准备数据(因此 min_max rows = 3)
我了解数据应采用以下格式 (('','','', ... 83 个条目), \ ('','','', ... 83 个条目) \ )
但我不知道如何将列表数据转换为记录 或者,或者,如何将 excel 数据直接读入 DF 可附加格式
tbl_tst.open(mode=dbf.READ_WRITE) # all fields character string
for everyrow in ws_IntMstDBF.iter_rows(min_row = 3, max_row = 3, max_col = ws_IntMstDBF.max_column-1):
datum = [] #set([83]), will defining datum as () help solve the problem?
for idx, cells in enumerate(everyrow):
if cells.value is None: # for None entries, enter empty string
datum.append("")
continue
datum.append(cells.value) # else enter cell values
tbl_tst.append(datum) # append that record to table !!! list is not record error here
tbl_tst.close()
错误是抱怨使用列表追加到表中,这应该是记录等。请指导我如何将 excel 行转换为可追加的 DBF 表数据。
raise TypeError("data to append must be a tuple, dict, record, or template; not a %r" % type(data))
TypeError: data to append must be a tuple, dict, record, or template; not a <class 'list'>
【问题讨论】: