我有一个Mongodb文档,我想用从表单收到的一些信息进行更新。 Mongodb中的原始文档具有以下数据:
.Cells(FndDt.Row,FndNum.Column) = "P"
从表格中获得的信息如下(其结构始终相同):
On Error Resume Next
为了从集合Option Explicit
Sub chrisellis250()
Dim Dt,Urn,i As Long,x As Long,lr As Long,lc As Long: x = 2
Dim colwidth As Long
Dim FndDt As Range,FndNum As Range,Dat As Date,Num As String,Loc As String
Dat = TimeValue("00:00:00")
Application.ScreenUpdating = False
With Sheet2
lr = .Cells(.Rows.Count,2).End(xlUp).Row
.Range(.Cells(2,1),.Cells(.Rows.Count,1)).AdvancedFilter xlFilterCopy,.Range("E1"),True
With .Range("E1").CurrentRegion: Dt = .Value: End With
Sheet1.Range("A3").Resize(UBound(Dt) - 1) = .Range("E2:E" & UBound(Dt)).Value: .Columns(5).Clear
Sheet1.Range("A3").Resize(UBound(Dt) - 1).Interior.ColorIndex = 15
.Range(.Cells(2,2),2)).AdvancedFilter xlFilterCopy,True
With .Range("E1").CurrentRegion: Urn = .Value: End With
For i = 1 To 2
Sheet1.Cells(2,x).Resize(,UBound(Urn) - 1) = Application.WorksheetFunction.Transpose(.Range("E2:E" & UBound(Urn)).Value)
If i = 1 Then colwidth = 8.3 Else colwidth = 55
Sheet1.Cells(2,UBound(Urn) - 1).ColumnWidth = colwidth
If x = 2 Then Sheet1.Cells(1,x) = "URN" Else Sheet1.Cells(1,x) = "XXXXX"
Sheet1.Cells(1,UBound(Urn) - 1).MergeCells = True
Sheet1.Cells(1,UBound(Urn) - 1).Interior.ColorIndex = 15
x = x + UBound(Urn) - 1
Next i
.Columns(5).Clear
For i = 2 To .Cells(.Rows.Count,1).End(xlUp).Row
If .Range("B" & i) <> "" Then
Dat = .Range("A" & i): Num = .Range("B" & i): Loc = .Range("C" & i)
With Sheet1
.Range("B3").Resize(lr,UBound(Urn) - 1).Font.Name = "Wingdings 2"
lc = .Cells(2,.Columns.Count).End(xlToLeft).Column
Set FndDt = .Range("A:A").Find(Dat,LookIn:=xlValues,lookat:=xlWhole)
Set FndNum = .Range(.Cells(2,.Cells(2,lc)).Find(Num,lookat:=xlWhole)
.Cells(FndDt.Row,FndNum.Column) = "P": .Cells(FndDt.Row,FndNum.Column).Font.Color = vbGreen
On Error Resume Next
If Not .Cells(FndDt.Row,FndNum.Column + UBound(Urn) - 1) Like "*" & Loc & "*" Then
.Cells(FndDt.Row,FndNum.Column + UBound(Urn) - 1) = IIf(.Cells(FndDt.Row,FndNum.Column + UBound(Urn) - 1) = "",Loc,.Cells(FndDt.Row,FndNum.Column + UBound(Urn) - 1) & "," & Loc)
End If
End With
End If
Next i
With Sheet1
With .Range("B3").Resize(UBound(Dt) - 1,UBound(Urn) - 1)
.SpecialCells(xlCellTypeBlanks).Font.Color = vbRed: .SpecialCells(xlCellTypeBlanks).Value = "O":
End With
With .Range("B3").Offset(,UBound(Urn) - 1).Resize(UBound(Urn) - 1,UBound(Urn) - 1)
.SpecialCells(xlCellTypeBlanks).Interior.ColorIndex = 15
End With
AddOutsideBorders .Range("A1").Resize(UBound(Dt) + 1,1 + ((UBound(Urn) - 1) * 2))
With .Cells
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.RowHeight = 25
End With
End With
End With
Application.ScreenUpdating = True
End Sub
Public Function AddOutsideBorders(rng As Range)
With rng.Borders
.Linestyle = xlContinuous
.Color = vbBlack
.Weight = xlThin
End With
End Function
中更新此文档,我正在执行以下操作:
{"id":1,"name": "James","surname1": "Adams"} [id is univoque]
这将为id = 1
name = "James"
surname1 = "Adams"
surname2 = ""
synced = 1
创建一个空字段。这是我的问题:在Mongodb中仅将那些不为空的字段插入的最pythonic方法是什么?可以使用内部Mongodb逻辑来完成此操作,还是只能通过对输入数据进行一些Python检查来完成?