我有以下代码从MongoDB获取数据并将其写入excel,但是当我打开生成的工作簿时它会出错("我们在~workbook_name中发现了一个问题〜..." )。
代码:
ws = wb.active
client = pymongo.MongoClient("...")
db = client['...']
collection = db['...']
r = 2
for doc in collection.find({'is_timeline_valid': True}):
for dic in doc['timeline']['datas']:
if 'pedido' in dic['tramite'].lower():
ws.cell(row = r, column = 1).value =doc['id_process_unformatted']
ws.cell(row = r, column = 2).value = dic['data']
ws.cell(row = r, column = 3).value = dic['tramite']
wb.save('pedido.xlsx')
print('*****************************')
print(dic['tramite'])
# print('check!')
r += 1