import pymongo
import xlwings as xw
connection = pymongo.MongoClient('mongodb://localhost:27017')
db = connection.sem
#連接本地?cái)?shù)據(jù)庫(kù)
rkfall = list(db.rkeys.find({}))?
rktemp = [] ?
[rktemp.append([i['_id'],i['rkclass'],i['rkweight'],i['rkadd']]) for i in rkfall]?
#“rkeys”為數(shù)據(jù)庫(kù)某個(gè)表的名稱簇爆,該表為字典存儲(chǔ)方式。讀取整表組成數(shù)組賦值。
#kwfall = list(db.keywords.find({'validity.Bayes':{'$gte':0.6}})),讀取表格內(nèi)部分文件參考
#新建空數(shù)組用來(lái)暫存取出的數(shù)據(jù)蚕甥。
#將整表部分?jǐn)?shù)據(jù)添加至“rktemp”空數(shù)組中崎溃,此步驟需循環(huán)讀取运敢。
sht = xw.books('test.xlsx').sheets('rkeys')?
sht.range('A2').value = rktemp?
#“test.xlsx”表格名稱邑遏,“rkeys”為sheets名稱另玖,此步驟需提前完成困曙,并保持打開表伦。
#從A2行開始將數(shù)據(jù)寫入sheets為“rkeys”表中。