我正在尝试从 Lotus Notes 数据库(使用 Designer 7.0)导出所有文档及其附件。我可以获取文档数据并获取附件,但前提是我对名称进行了硬编码。我发现在 LotusScript 中以编程方式获取文件名的这两种方法都不起作用,如下面的两个代码块所示。在第一个中, doc.GetFirstItem( "Body" ) 返回 Nothing,在第二个中,在 Forall 行上执行期间存在类型不匹配。任何有关如何提取附件的帮助将不胜感激!我不确定附件是存储为“附件”还是 OLE,但我怀疑是附件,因为它们主要是 PDF。
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