Import to xlrd Import JSON Import pymongo # connection database Client = pymongo.MongoClient ( ' localhost ' , 27017 ) mydb = Client [ ' douban ' ] info = mydb [ ' Data ' ] # read Excel file Data = xlrd.open_workbook ( ' Data * .xls ' ) Table = data.sheets () [0] # read excel as the first line of data field names stored in the mongodb rowstag = table.row_values (0) nrows =table.nrows returndata = {} for I in Range (. 1 , nrows): # The data field names and excel as dictionary form, the format and converted to json returndata [I] = json.dumps (dict (ZIP (rowstag, Table. row_values (I)))) # by reducing data codec returndata [I] = json.loads (returndata [I]) info.insert_one (returndata [I])