zoukankan      html  css  js  c++  java
  • MongoDB

    import pymongo
    import re
    
    client = pymongo.MongoClient('127.0.0.1', 27017)
    db_name = 'Trade'
    
    db = client[db_name]
    
    
    filter1 = {'$or':[{"phone": {'$ne':""}}, {"cell_phone": {'$ne':""}}]}
    filter2 = {'address':1, 'contact':1, 'phone':1, 'cell_phone':1, '_id':0}
    
    results = db.business.find(filter1, filter2)
    
    from openpyxl import Workbook
    wb = Workbook()
    
    # grab the active worksheet
    ws = wb.active
    
    ws.append(('地址', '联系人', '电话', '手机'))
    # for _ in a:
    #     print(a.next())
    
    for data in results:
        address = data['address']
        contact = data['contact']
        phone = data['phone']
        cell_phone = data['cell_phone']
        result = (address, contact, phone, cell_phone)
        ws.append(result)
    
    wb.save("sample.xlsx")
    
  • 相关阅读:
    Permutations II
    N-Queens II
    Palindrome Number
    Minimum Path Sum
    JS的DOM操作2
    JS 的DOM操作
    函数概念
    JavaScript数组
    JavaScript循环及练习
    JS语言
  • 原文地址:https://www.cnblogs.com/allen2333/p/9580310.html
Copyright © 2011-2022 走看看