我試圖從Lotus Notes數據庫(使用Designer 7.0)導出所有文檔及其附件。我可以獲取文檔數據並可以獲得附件,但前提是需要對名稱進行硬編碼。在LotusScript中,我發現以編程方式獲取文件名的兩種方法不起作用,如下面兩個代碼塊所示。在第一個中,doc.GetFirstItem(「Body」)返回Nothing,第二個,在Forall行上執行時會出現類型不匹配。 如何提取附件的任何幫助將不勝感激!我不確定附件是否以「附件」或OLE存儲,但我懷疑是附件,因爲它們主要是PDF。如何檢索Lotus Notes附件?
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim query As String
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim fileCount As Integer
Dim attachment As NotesEmbeddedObject
Dim fileName As String
Set db = session.CurrentDatabase
' get a document that has an attachment
Set collection = db.FTSearch("06/25/2013", 10)
fileNum% = Freefile()
fileName$ = "c:\kcw\lotusexport.txt"
Open fileName$ For Output As fileNum%
Write #fileNum%, "docs found", collection.Count
Set doc = collection.GetFirstDocument
' write out document properties
Forall x In doc.Items
Write #fileNum%, x.Name, " = ", x.Text
End Forall
'extract document (using hardcoded name)
Set attachment = doc.GetAttachment("OCSE-FRONT_SCANTODESKTOP_06262013-104822.pdf")
Call attachment.ExtractFile _
("c:\kcw\attachment")
'Try to get attachment through "Body", but rtitem is Nothing
Set rtitem = doc.GetFirstItem("Body")
Write #fileNum%, "rtitem is Nothing", rtitem Is Nothing
fileCount = 0
If Not rtitem Is Nothing Then
If (rtitem.Type = RICHTEXT) Then
Write #fileNum%, "rtitem is RICHTEXT"
Forall o In rtitem.EmbeddedObjects
Write #fileNum%, "has Embedded Objects"
fileCount = fileCount + 1
Write #fileNum%,"rtitem num", fileCount
Call o.ExtractFile _
("c:\kcw\newfile" & Cstr(fileCount))
End Forall
End If
End If
'Fails with "Type mismatch" at Forall loop
If doc.HasEmbedded Then
Write #fileNum%, "doc has embedded"
Forall objects In doc.EmbeddedObjects
Write #fileNum%, "in for loop"
Write #fileNum%, "filename= ", object.Source
End Forall
End If
Close fileNum%
End Sub
Dim session ..etc。是什麼意思? – zanbri
Body字段是否存在於每個文檔中?非常奇怪,它什麼都沒有返回。 –
你絕對應該看看LotusScript中的錯誤處理技術。在循環中處理文檔可能會有一些問題 - 隨時可以處理。剛剛從所述頭部的頂部:不同形式(無體字段),損壞的DOC(.isValid),無效的文件名等(內部附件的名稱可以從一個客戶端中所示不同)。 –